﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.IO
Imports System.Diagnostics
Imports DevExpress.XtraEditors
Imports DevExpress.Skins
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraBars.Ribbon.Gallery
Imports DevExpress.Utils.Drawing
Imports DevExpress.Utils
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.LookAndFeel
Imports System.Collections.Generic
Imports System.Text
Imports DevExpress.XtraBars.Helpers
Imports DevExpress.XtraTab
Imports System.Math
Public Class frm_main
    Private congtruong As congtruong
    Private datda As datda
    Private maykhoan As maykhoan
    Private lokhoan As lokhoan
    Private thuocno As thuocno
    Private kipno As kipno
    Private dayno As dayno
    Private maynomin As maynomin
    Private ppno As phuongphapno
    Private bus As knm2012BUS
    Private dao As knm2012DAO
    Private cm As CurrencyManager
    Dim Wfrm As Integer, Hfrm As Integer, Hmenu As Integer
    Dim hLcWnd As Integer, hLcDrw As Integer, hLcProp As Integer, hLcCmd As Integer, hLcStt As Integer, hEnt As Integer
    Dim EventGripMove As F_GRIPMOVE
    Dim EventGetPoint As F_GETPOINT
    Dim EventMouseMove As F_MOUSEMOVE
    Dim EventPaint As F_PAINT
    Dim EventAddCommand As F_ADDCOMMAND
    Dim EventCmdStart As F_CMD_START
    Dim EventCmdFinish As F_CMD_FINISH
    Dim EventCmdMouseDown As F_CMD_MOUSEDOWN
    Dim EventCmdMouseUp As F_CMD_MOUSEUP
    Dim EventCmdMouseMove As F_CMD_MOUSEMOVE
    Dim EventCmdString As F_CMD_STRING
    Dim hView As Integer
    Dim hBlock As Integer
    Dim hText As Integer
    Public Const PROP_WIDTH = 200
    Public Const MYCMD_SKETCH = Lcad.LC_CMD_CUSTOM + 1
    Declare Function SetPixel Lib "gdi32" Alias "SetPixel" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Integer) As Integer
    Private Sub RibbonForm1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'KNM2012DataSet.ThongSoQuyDinh' table. You can move, or remove it, as needed.
        Me.ThongSoQuyDinhTableAdapter.Fill(Me.KNM2012DataSet.ThongSoQuyDinh)
        'TODO: This line of code loads data into the 'KNM2012DataSet.HCKNM' table. You can move, or remove it, as needed.
        Me.HCKNMTableAdapter.Fill(Me.KNM2012DataSet.HCKNM)
        'TODO: This line of code loads data into the 'KNM2012DataSet.PKNo' table. You can move, or remove it, as needed.
        Me.PKNoTableAdapter.Fill(Me.KNM2012DataSet.PKNo)
        'TODO: This line of code loads data into the 'KNM2012DataSet.PPNo' table. You can move, or remove it, as needed.
        Me.PPNoTableAdapter.Fill(Me.KNM2012DataSet.PPNo)
        'TODO: This line of code loads data into the 'KNM2012DataSet.MayNoMin' table. You can move, or remove it, as needed.
        Me.MayNoMinTableAdapter.Fill(Me.KNM2012DataSet.MayNoMin)
        'TODO: This line of code loads data into the 'KNM2012DataSet.DayNo' table. You can move, or remove it, as needed.
        Me.DayNoTableAdapter.Fill(Me.KNM2012DataSet.DayNo)
        'TODO: This line of code loads data into the 'KNM2012DataSet.KipNo' table. You can move, or remove it, as needed.
        Me.KipNoTableAdapter.Fill(Me.KNM2012DataSet.KipNo)
        'TODO: This line of code loads data into the 'KNM2012DataSet.ThuocNo' table. You can move, or remove it, as needed.
        Me.ThuocNoTableAdapter.Fill(Me.KNM2012DataSet.ThuocNo)
        'TODO: This line of code loads data into the 'KNM2012DataSet.LoKhoan' table. You can move, or remove it, as needed.
        Me.LoKhoanTableAdapter.Fill(Me.KNM2012DataSet.LoKhoan)
        'TODO: This line of code loads data into the 'KNM2012DataSet.MayKhoan' table. You can move, or remove it, as needed.
        Me.MayKhoanTableAdapter.Fill(Me.KNM2012DataSet.MayKhoan)
        'TODO: This line of code loads data into the 'KNM2012DataSet.DatDa' table. You can move, or remove it, as needed.
        Me.DatDaTableAdapter.Fill(Me.KNM2012DataSet.DatDa)
        'TODO: This line of code loads data into the 'KNM2012DataSet.CongTruong' table. You can move, or remove it, as needed.
        Me.CongTruongTableAdapter.Fill(Me.KNM2012DataSet.CongTruong)



        Lcad.Initialize("")
        EventMouseMove = New F_MOUSEMOVE(AddressOf ProcMouseDown)
        Call Lcad.OnEventMouseMove(EventMouseMove)
        EventGripMove = New F_GRIPMOVE(AddressOf ProcGripMove)
        Call Lcad.OnEventGripMove(EventGripMove)
        EventGetPoint = New F_GETPOINT(AddressOf ProcGetPoint)
        Call Lcad.OnEventGetPoint(EventGetPoint)
        Call Lcad.OnEventPaint(EventPaint)
        EventAddCommand = New F_ADDCOMMAND(AddressOf ProcAddCommand)
        Call Lcad.OnEventAddCommand(EventAddCommand)
        EventCmdStart = New F_CMD_START(AddressOf ProcCmdStart)
        Call Lcad.OnEventCmdStart(EventCmdStart)
        EventCmdFinish = New F_CMD_FINISH(AddressOf ProcCmdFinish)
        Call Lcad.OnEventCmdFinish(EventCmdFinish)
        EventCmdMouseDown = New F_CMD_MOUSEDOWN(AddressOf ProcCmdMouseDown)
        Call Lcad.OnEventCmdMouseDown(EventCmdMouseDown)
        EventCmdMouseUp = New F_CMD_MOUSEUP(AddressOf ProcCmdMouseUp)
        Call Lcad.OnEventCmdMouseUp(EventCmdMouseUp)
        EventCmdMouseMove = New F_CMD_MOUSEMOVE(AddressOf ProcCmdMouseMove)
        Call Lcad.OnEventCmdMouseMove(EventCmdMouseMove)
        EventCmdString = New F_CMD_STRING(AddressOf ProcCmdString)
        hLcWnd = Lcad.CreateWindow(SplitContainer3.Panel2.Handle, LC_WS_DEFAULT, 0, 0, SplitContainer3.Panel2.Width, SplitContainer3.Panel2.Height)
        hLcDrw = Lcad.CreateDrawing()
        'hView = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_VIEW)
        'hBlock = Lcad.PropGetHandle(hView, LC_PROP_VIEW_BLOCK)
        'hView = Lcad.PropGetHandle(hLcDrw, LC_PROP_DRW_VIEW)
        'hView = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_VIEW)
        hView = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_VIEW)
        hBlock = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_BLOCK)
        Lcad.PropPutBool(hView, LC_PROP_VIEW_GRID, False)
        Lcad.WndSelectView(hLcWnd, hView)
        Lcad.WndSetFocus(hLcWnd)
        Lcad.DrwNew(hLcDrw, "", hLcWnd)
        hLcProp = Lcad.CreatePropwin(SplitContainer6.Panel2.Handle, 0, 0, SplitContainer6.Panel2.Width, SplitContainer6.Panel2.Height)
        Lcad.WndSetPropwin(hLcWnd, hLcProp)
        hLcCmd = Lcad.CreateCmdwin(SplitContainer5.Panel1.Handle, 0, 0, SplitContainer5.Panel1.Width, SplitContainer5.Panel1.Height)
        Lcad.WndSetCmdwin(hLcWnd, hLcCmd)
        Lcad.WndExeCommand(hLcWnd, LC_CMD_ZOOM_EXT, 0)
        Lcad.CmdwinResize(hLcCmd, 0, 0, SplitContainer5.Panel1.Width, SplitContainer5.Panel1.Height)
        Lcad.PropwinResize(hLcProp, 0, 0, SplitContainer6.Panel2.Width, SplitContainer6.Panel2.Height)
        Lcad.WndResize(hLcWnd, 0, 0, SplitContainer3.Panel2.Width, SplitContainer3.Panel2.Height)
        'Lcad.WndRedraw(hLcWnd)
        Lcad.Uninitialize(False)
        Lcad.PropPutBool(hView, LC_PROP_VIEW_GRID, False)
        Lcad.PropPutBool(hView, LC_PROP_VIEW_GRIDSNAP, False)


        DevExpress.UserSkins.BonusSkins.Register()
        DevExpress.UserSkins.OfficeSkins.Register()
        SkinHelper.InitSkinGallery(RibbonGalleryBarItem1, True)
        EnableTab(False)
        'LoadDataCongTruong()
        'LoadDataDatDa()
        'LoadDataMayKhoan()
        'LoadDataLokhoan()
        'LoadDataThuocNo()
        'LoadDataKipNo()
        'LoadDataDayNo()
        'LoadDataMayNo()
        'LoadDataHoChieu()
        tabcontrol.Visible = True
        BarEditItem1.EditValue = Image.FromFile("logo1.png")

     
    End Sub

    
#Region "tabcontrol"
    Private Sub EnableTab(ByVal t As Boolean)
        tabcongtruong.PageVisible = t
        tabdatda.PageVisible = t
        tabmaykhoan.PageVisible = t
        tablokhoan.PageVisible = t
        tabthuocno.PageVisible = t
        tabkipno.PageVisible = t
        tabdayno.PageVisible = t
        tabmaynomin.PageVisible = t
        tabppno.PageVisible = t
        tabphukien.PageVisible = t
        tabtinhtoan.PageVisible = t
        tabhochieu.PageVisible = t
        tabbanve.PageVisible = t
        tabxemlaihc.PageVisible = t
    End Sub
    Private Sub TestTab(ByVal tabkt As DevExpress.XtraTab.XtraTabPage)
        Dim kt As Integer = 0
        For Each tabpage As DevExpress.XtraTab.XtraTabPage In tabcontrol.TabPages
            If (tabpage.Name = tabkt.AccessibleName) Then
                kt = 1
            End If
        Next
        If kt = 1 Then
            tabcontrol.SelectedTabPage = tabkt
        Else
            tabcontrol.TabPages.Add(tabkt)
            tabkt.PageVisible = True
            tabcontrol.SelectedTabPage = tabkt
        End If
    End Sub
#End Region

#Region "CloseTab"
    Private Sub tabcontrol_CloseButtonClick(sender As System.Object, e As System.EventArgs) Handles tabcontrol.CloseButtonClick
        If (flagct = 0 And flagdd = 0 And flagmk = 0 And flaglk = 0 And flagtn = 0 And flagkn = 0) Then
            tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
        End If

        If (flagct <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavect.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncancelct.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flagdd <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavedd.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncanceldd.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flagmk <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavemk.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncancelmk.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flaglk <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavelk.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncancellk.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flagtn <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavetn.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncanceltn.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flagkn <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavekip.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncancelkip.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flagdn <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavedn.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncanceldn.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flagmn <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavemn.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncancelmn.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flagppn <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsaveppn.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncancelppn.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flagpk <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavepk.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncancelpk.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If

        If (flaghc <> 0) Then
            If (MessageBox.Show("Lưu dữ liệu trước khi đóng tab?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
                btnsavehc.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            Else
                btncancelhc.PerformClick()
                tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
            End If
        End If


    End Sub
#End Region

#Region "OpenTab"
    Private Sub btncongtruong_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btncongtruong.ItemClick
        TestTab(tabcongtruong)
        LookButtonCT(False)
        LookDropButtonCT(True)
        ClearBindingCT()
        LoadDataCongTruong()
        flagct = 0
        tabcontrol.Visible = True
    End Sub

    Private Sub btndatda_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btndatda.ItemClick
        TestTab(tabdatda)
        LookButtonDD(False)
        LookDropButtonDD(True)
        ClearBindingDD()
        LoadDataDatDa()
        flagdd = 0
        tabcontrol.Visible = True
    End Sub

    Private Sub btnmaykhoan_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnmaykhoan.ItemClick
        TestTab(tabmaykhoan)
        LookButtonMK(False)
        LookDropButtonMK(True)
        ClearBindingMK()
        LoadDataMayKhoan()
        flagmk = 0
        tabcontrol.Visible = True
    End Sub

    Private Sub btnlokhoan_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnlokhoan.ItemClick
        TestTab(tablokhoan)
        LookButtonLK(False)
        LookDropButtonLK(True)
        ClearBindingLK()
        LoadDataLokhoan()
        flaglk = 0
        tabcontrol.Visible = True
    End Sub

    Private Sub btnthuocno_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnthuocno.ItemClick
        TestTab(tabthuocno)
        LookButtonTN(False)
        LookDropButtonTN(True)
        ClearBindingTN()
        LoadDataThuocNo()
        flagct = 0
        tabcontrol.Visible = True
    End Sub

    Private Sub btnkipno_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnkipno.ItemClick
        TestTab(tabkipno)
        LookButtonKN(False)
        LookDropButtonKN(True)
        ClearBindingKN()
        LoadDataKipNo()
        flagkn = 0
        tabcontrol.Visible = True
    End Sub

    Private Sub btndayno_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btndayno.ItemClick
        TestTab(tabdayno)
        LookButtonDN(False)
        LookDropButtonDN(True)
        ClearBindingDN()
        LoadDataDayNo()
        flagdn = 0
        tabcontrol.Visible = True
    End Sub

    Private Sub btnmayno_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnmayno.ItemClick
        TestTab(tabmaynomin)
        LookButtonMN(False)
        LookDropButtonMN(True)
        ClearBindingMN()
        LoadDataMayNo()
        flagmn = 0
        tabcontrol.Visible = True
    End Sub
    Private Sub btnphukien_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnphukien.ItemClick
        TestTab(tabphukien)
        LookButtonPK(False)
        LookDropButtonPK(True)
        ClearBindingPK()
        LoadDataPKNo()
        flagpk = 0
        tabcontrol.Visible = True
    End Sub

    Private Sub btnppno_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnppno.ItemClick
        TestTab(tabppno)
        LookButtonPPN(False)
        LookDropButtonPPN(True)
        ClearBindingPPN()
        LoadDataPPNo()
        flagppn = 0
        tabcontrol.Visible = True
    End Sub
    Private Sub btnhochieu_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnhochieu.ItemClick
        TestTab(tabhochieu)
        LookButtonHC(False)
        LookDropButtonHC(True)
        ClearBindingHC()
        LoadDataHoChieu()
        flaghc = 0
        tabcontrol.Visible = True
    End Sub

    Private Sub btntinhtoan_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btntinhtoan.ItemClick
        TestTab(tabtinhtoan)
        tabcontrol.Visible = True
    End Sub
    Private Sub btncad_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btncad.ItemClick
        TestTab(tabbanve)
        ToolStrip1.Visible = True
        ToolStrip2.Visible = True
        ToolStrip3.Visible = True
        tabcontrol.Visible = True
    End Sub
    Private Sub btnxemlaihc_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnxemlaihc.ItemClick
        TestTab(tabxemlaihc)
        tabcontrol.Visible = True
    End Sub
#End Region

#Region "page_hethong"
    Private Sub btnbackup_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnbackup.ItemClick
        frm_backup.Show()
    End Sub

    Private Sub btnexit_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnexit.ItemClick
        If (MessageBox.Show("Bạn có chắc chắn muốn thoát", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
            Me.Close()
            Global.System.Windows.Forms.Application.Exit()
        End If
    End Sub

    Private Sub btnrestore_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnrestore.ItemClick
        frm_restore.Show()
    End Sub
    Private Sub btnmnuexit_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnmnuexit.ItemClick
        Me.Close()
        Global.System.Windows.Forms.Application.Exit()
    End Sub
    Private Sub BarEditItem1_ItemPress(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarEditItem1.ItemPress
        System.Diagnostics.Process.Start("http://itclub.humg.edu.vn")
    End Sub

#End Region

#Region "page_quanlydulieu"

#Region "tabcongtruong"
    Dim flagct As Integer = 0
    Dim testct As Integer = 0
    Private Sub LoadDataCongTruong()
        dgvcongtruong.RefreshDataSource()
        bus = New knm2012BUS
        Dim knmList As New List(Of congtruong)
        knmList = bus.GetDataCT()
        cm = Me.BindingContext(knmList)
        txtmacongtruong.DataBindings.Add("Text", knmList, "Macongtruong")
        txttencongtruong.DataBindings.Add("Text", knmList, "Tencongtruong")
        txtcaodiem.DataBindings.Add("Text", knmList, "Caodiem")
        txttang.DataBindings.Add("Text", knmList, "Tang")
        txtkhuvuc.DataBindings.Add("Text", knmList, "Khuvuc")
        txtn.DataBindings.Add("Text", knmList, "N")
        txte.DataBindings.Add("Text", knmList, "E")
        dgvcongtruong.DataSource = knmList
    End Sub
    Public Sub ClearBindingCT()
        txtmacongtruong.DataBindings.Clear()
        txttencongtruong.DataBindings.Clear()
        txtcaodiem.DataBindings.Clear()
        txttang.DataBindings.Clear()
        txtkhuvuc.DataBindings.Clear()
        txtn.DataBindings.Clear()
        txte.DataBindings.Clear()
    End Sub
    Private Sub LookButtonCT(ByVal l As Boolean)
        btnaddct.Enabled = Not l
        btneditct.Enabled = Not l
        btndeletect.Enabled = Not l
        btnsavect.Enabled = l
        btncancelct.Enabled = l
        btnclosect.Enabled = Not l
    End Sub
    Private Sub LookDropButtonCT(ByVal l As Boolean)
        editmacongtruong.Enabled = Not l
        edittencongtruong.Enabled = Not l
        editcaodiem.Enabled = Not l
        edittang.Enabled = Not l
        editkhuvuc.Enabled = Not l
        editn.Enabled = Not l
        edite.Enabled = Not l
    End Sub
    Private Function TestTextboxCT()
        If (Trim(txtmacongtruong.Text = "") Or Trim(txttencongtruong.Text) = "" Or Trim(txtcaodiem.Text) = "" Or Trim(txttang.Text) = "" Or Trim(txtkhuvuc.Text) = "" Or Trim(txtn.Text) = "" Or Trim(txte.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin, vui lòng kiểm tra lại! ", MsgBoxStyle.Exclamation, "Thông báo")
            txtmacongtruong.Focus()
            testct = 0
        Else
            testct = 1
        End If
        Return testct
    End Function
    Private Sub ClearTextboxCT()
        txtmacongtruong.Text = ""
        txttencongtruong.Text = ""
        txtcaodiem.Text = ""
        txttang.Text = ""
        txtkhuvuc.Text = ""
        txtn.Text = ""
        txte.Text = ""
    End Sub
    Private Sub editn_TextChanged(sender As System.Object, e As System.EventArgs) Handles editn.TextChanged
        txtn.Text = editn.Text
    End Sub
    Private Sub edite_TextChanged(sender As System.Object, e As System.EventArgs) Handles edite.TextChanged
        txte.Text = edite.Text
    End Sub
    Private Sub editmacongtruong_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmacongtruong.TextChanged
        txtmacongtruong.Text = editmacongtruong.Text
    End Sub

    Private Sub edittencongtruong_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittencongtruong.TextChanged
        txttencongtruong.Text = edittencongtruong.Text
    End Sub

    Private Sub editcaodiem_TextChanged(sender As System.Object, e As System.EventArgs) Handles editcaodiem.TextChanged
        txtcaodiem.Text = editcaodiem.Text
    End Sub
    Private Sub edittang_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittang.TextChanged
        txttang.Text = edittang.Text
    End Sub

    Private Sub editkhuvuc_TextChanged(sender As System.Object, e As System.EventArgs) Handles editkhuvuc.TextChanged
        txtkhuvuc.Text = editkhuvuc.Text
    End Sub

    Private Sub btnadd_Click(sender As System.Object, e As System.EventArgs) Handles btnaddct.Click
        ClearTextboxCT()
        flagct = 1
        txtmacongtruong.Focus()
        LookDropButtonCT(False)
        LookButtonCT(True)
    End Sub
    Private Sub btnedit_Click(sender As System.Object, e As System.EventArgs) Handles btneditct.Click
        flagct = 2
        txtmacongtruong.Enabled = False
        txttencongtruong.Focus()
        LookDropButtonCT(False)
        LookButtonCT(True)
        editmacongtruong.Enabled = False
    End Sub
    Private Sub btndelete_Click(sender As System.Object, e As System.EventArgs) Handles btndeletect.Click
        Dim macongtruong As String = txtmacongtruong.Text
        Dim tencongtruong As String = txttencongtruong.Text
        Dim caodiem As String = txtcaodiem.Text
        Dim tang As String = txttang.Text
        Dim khuvuc As String = txtkhuvuc.Text
        Dim n As Double = txtn.Text
        Dim e_ As Double = txte.Text
        congtruong = New congtruong(macongtruong, tencongtruong, caodiem, tang, khuvuc, n, e_)
        bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
            bus.DeleteCT(congtruong)
            ClearBindingCT()
            LoadDataCongTruong()
            LookButtonCT(False)
            LookDropButtonCT(True)
            MsgBox("Bạn đã xóa thành công!", MsgBoxStyle.Information, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa!", MsgBoxStyle.Information, "Thông báo")
        End If
    End Sub

    Private Sub btncancelct_Click(sender As System.Object, e As System.EventArgs) Handles btncancelct.Click
        flagct = 0
        txtmacongtruong.Enabled = True
        ClearBindingCT()
        LoadDataCongTruong()
        LookButtonCT(False)
        LookDropButtonCT(True)
        dgvcongtruong.RefreshDataSource()
    End Sub
    Private Sub btnsave_Click(sender As System.Object, e As System.EventArgs) Handles btnsavect.Click
        Dim macongtruong As String = txtmacongtruong.Text
        Dim tencongtruong As String = txttencongtruong.Text
        Dim caodiem As String = txtcaodiem.Text
        Dim tang As String = txttang.Text
        Dim khuvuc As String = txtkhuvuc.Text
        Dim n As Double = txtn.Text
        Dim e_ As Double = txte.Text
        TestTextboxCT()
        If (testct = 1) Then
            congtruong = New congtruong(macongtruong, tencongtruong, caodiem, tang, khuvuc, n, e_)
            bus = New knm2012BUS
            bus.InsertUpdateCT(congtruong, flagct)
            ClearBindingCT()
            LoadDataCongTruong()
            LookButtonCT(False)
            LookDropButtonCT(True)
            dgvcongtruong.RefreshDataSource()
            txtmacongtruong.Enabled = True
        End If
    End Sub
    Private Sub btnclose_Click(sender As System.Object, e As System.EventArgs) Handles btnclosect.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub

#End Region

#Region "tabdatda"
    Dim flagdd As Integer = 0
    Dim testdd As Integer = 0
    Private Sub LoadDataDatDa()
        dgvdatda.RefreshDataSource()
        bus = New knm2012BUS
        Dim ddList As New List(Of datda)
        ddList = bus.GetDataDD()
        cm = Me.BindingContext(ddList)
        txtmadatda.DataBindings.Add("Text", ddList, "Madatda")
        txttendatda.DataBindings.Add("Text", ddList, "Tendatda")
        txtdocung.DataBindings.Add("Text", ddList, "Docung")
        dgvdatda.DataSource = ddList
    End Sub
    Private Sub ClearBindingDD()
        txtmadatda.DataBindings.Clear()
        txttendatda.DataBindings.Clear()
        txtdocung.DataBindings.Clear()
    End Sub
    Private Sub LookButtonDD(ByVal l As Boolean)
        btnadddd.Enabled = Not l
        btneditdd.Enabled = Not l
        btndeletedd.Enabled = Not l
        btnsavedd.Enabled = l
        btncanceldd.Enabled = l
        btnclosedd.Enabled = Not l
    End Sub
    Private Sub LookDropButtonDD(ByVal l As Boolean)
        editmadatda.Enabled = Not l
        edittendatda.Enabled = Not l
        editdocung.Enabled = Not l
    End Sub
    Private Sub ClearTextboxDD()
        txtmadatda.Text = ""
        txttendatda.Text = ""
        txtdocung.Text = ""
    End Sub
    Private Sub editmadatda_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmadatda.TextChanged
        txtmadatda.Text = editmadatda.Text
    End Sub

    Private Sub edittendatda_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittendatda.TextChanged
        txttendatda.Text = edittendatda.Text
    End Sub

    Private Sub editdocung_TextChanged(sender As System.Object, e As System.EventArgs) Handles editdocung.TextChanged
        txtdocung.Text = editdocung.Text
    End Sub
    Private Sub btnadddd_Click(sender As System.Object, e As System.EventArgs) Handles btnadddd.Click
        ClearTextboxDD()
        flagdd = 1
        txtmadatda.Focus()
        LookDropButtonDD(False)
        LookButtonDD(True)
    End Sub
    Private Sub btneditdd_Click(sender As System.Object, e As System.EventArgs) Handles btneditdd.Click
        flagdd = 2
        txtmadatda.Enabled = False
        txttendatda.Focus()
        LookDropButtonDD(False)
        LookButtonDD(True)
        editmadatda.Enabled = False
    End Sub
    Private Sub btndeletedd_Click(sender As System.Object, e As System.EventArgs) Handles btndeletedd.Click
        Dim madatda As String = txtmadatda.Text
        Dim tendatda As String = txttendatda.Text
        Dim docung As Single = CSng(txtdocung.Text)
        datda = New datda(madatda, tendatda, docung)
        bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
            bus.DeleteDD(datda)
            ClearBindingDD()
            LoadDataDatDa()
            LookButtonDD(False)
            LookDropButtonDD(True)
            MsgBox("Bạn đã xóa thành công!", MsgBoxStyle.Information, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa!", MsgBoxStyle.Information, "Thông báo")
        End If
    End Sub
    Private Sub btnsavedd_Click(sender As System.Object, e As System.EventArgs) Handles btnsavedd.Click
        TestTextboxDD()
        If testdd = 1 Then
            Dim madatda As String = txtmadatda.Text
            Dim tendatda As String = txttendatda.Text
            Dim docung As Single = Convert.ToSingle(txtdocung.Text)
            datda = New datda(madatda, tendatda, docung)
            bus = New knm2012BUS
            bus.InsertUpdateDD(datda, flagdd)
            ClearBindingDD()
            LoadDataDatDa()
            LookButtonDD(False)
            LookDropButtonCT(True)
            dgvdatda.RefreshDataSource()
            txtmadatda.Enabled = True
        End If
    End Sub
    Private Function TestTextboxDD()
        If ((Trim(txtmadatda.Text) = "") Or (Trim(txttendatda.Text) = "") Or (Trim(txtdocung.Text) = "")) Then
            MsgBox("Bạn phải nhập đầy đủ thông tin, vui lòng kiểm tra lại!", MsgBoxStyle.Exclamation, "Thông báo")
            txtmadatda.Focus()
            testdd = 0
        ElseIf (CSng(txtdocung.Text) < 0 Or CSng(txtdocung.Text) > 20) Then
            MsgBox("Độ cứng nằm trong giới hạn từ 0 - 20 theo Protodiaconov", MsgBoxStyle.Exclamation, "Thông báo")
            txtdocung.Focus()
            testdd = 0
        Else
            testdd = 1
        End If
        Return testdd
    End Function
    Private Sub btncanceldd_Click(sender As System.Object, e As System.EventArgs) Handles btncanceldd.Click
        flagdd = 0
        txtmadatda.Enabled = True
        ClearBindingDD()
        LoadDataDatDa()
        LookButtonDD(False)
        LookDropButtonDD(True)
        dgvdatda.RefreshDataSource()
    End Sub
    Private Sub btnclosedd_Click(sender As System.Object, e As System.EventArgs) Handles btnclosedd.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#Region "tabmaykhoan"
    Dim flagmk As Integer = 0
    Dim testmk As Integer = 0
    Private Sub LoadDataMayKhoan()
        dgvdatda.RefreshDataSource()
        bus = New knm2012BUS
        Dim mkList As New List(Of maykhoan)
        mkList = bus.GetDataMK()
        cm = Me.BindingContext(mkList)
        txtmamaykhoan.DataBindings.Add("Text", mkList, "Mamaykhoan")
        txttenmaykhoan.DataBindings.Add("Text", mkList, "Tenmaykhoan")
        txtdkmuikhoan.DataBindings.Add("Text", mkList, "Dkmuikhoan")
        txtchieusaukhoantd.DataBindings.Add("Text", mkList, "Chieusaukhoantd")
        txthuongkhoan.DataBindings.Add("Text", mkList, "Huongkhoan")
        dgvmaykhoan.DataSource = mkList
    End Sub
    Private Sub ClearBindingMK()
        txtmamaykhoan.DataBindings.Clear()
        txttenmaykhoan.DataBindings.Clear()
        txtchieusaukhoantd.DataBindings.Clear()
        txtdkmuikhoan.DataBindings.Clear()
        txthuongkhoan.DataBindings.Clear()
    End Sub
    Private Sub LookButtonMK(ByVal l As Boolean)
        btnaddmk.Enabled = Not l
        btneditmk.Enabled = Not l
        btndeletemk.Enabled = Not l
        btnsavemk.Enabled = l
        btncancelmk.Enabled = l
        btnclosemk.Enabled = Not l
    End Sub
    Private Sub LookDropButtonMK(ByVal l As Boolean)
        editmamaykhoan.Enabled = Not l
        edittenmaykhoan.Enabled = Not l
        editchieusaukhoantoida.Enabled = Not l
        edithuongkhoan.Enabled = Not l
        editdkmuikhoan.Enabled = Not l
    End Sub
    Private Sub ClearTextboxMK()
        txtmamaykhoan.Text = ""
        txttenmaykhoan.Text = ""
        txtdkmuikhoan.Text = ""
        txtchieusaukhoantd.Text = ""
        txthuongkhoan.Text = ""
    End Sub
    Private Sub editmamaykhoan_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmamaykhoan.TextChanged
        txtmamaykhoan.Text = editmamaykhoan.Text
    End Sub

    Private Sub edittenmaykhoan_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittenmaykhoan.TextChanged
        txttenmaykhoan.Text = edittenmaykhoan.Text
    End Sub

    Private Sub editchieusaukhoantoida_TextChanged(sender As System.Object, e As System.EventArgs) Handles editchieusaukhoantoida.TextChanged
        txtchieusaukhoantd.Text = editchieusaukhoantoida.Text
    End Sub
    Private Sub editdkmuikhoan_TextChanged(sender As System.Object, e As System.EventArgs) Handles editdkmuikhoan.TextChanged
        txtdkmuikhoan.Text = editdkmuikhoan.Text
    End Sub
    Private Sub edithuongkhoan_TextChanged(sender As System.Object, e As System.EventArgs) Handles edithuongkhoan.TextChanged
        txthuongkhoan.Text = edithuongkhoan.Text
    End Sub
    Private Sub btnaddmk_Click(sender As System.Object, e As System.EventArgs) Handles btnaddmk.Click
        ClearTextboxMK()
        flagmk = 1
        txtmamaykhoan.Focus()
        LookDropButtonMK(False)
        LookButtonMK(True)
    End Sub
    Private Sub btneditmk_Click(sender As System.Object, e As System.EventArgs) Handles btneditmk.Click
        flagmk = 2
        txtmamaykhoan.Enabled = False
        txttenmaykhoan.Focus()
        LookDropButtonMK(False)
        LookButtonMK(True)
        editmamaykhoan.Enabled = False
    End Sub
    Private Sub btndeleteddmk_Click(sender As System.Object, e As System.EventArgs) Handles btndeletemk.Click
        Dim mamaykhoan As String = txtmamaykhoan.Text
        Dim tenmaykhoan As String = txttenmaykhoan.Text
        Dim dkmuikhoan As Single = Convert.ToSingle(txtdkmuikhoan.Text)
        Dim chieusaukhoantd As Single = Convert.ToSingle(txtchieusaukhoantd.Text)
        Dim huongkhoan As Single = Convert.ToSingle(txthuongkhoan.Text)
        maykhoan = New maykhoan(mamaykhoan, tenmaykhoan, dkmuikhoan, chieusaukhoantd, huongkhoan)
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
            bus.DeleteMK(maykhoan)
            ClearBindingMK()
            LoadDataMayKhoan()
            LookButtonMK(False)
            LookDropButtonMK(True)
            MsgBox("Bạn đã xóa thành công!", MsgBoxStyle.Information, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa!", MsgBoxStyle.Information, "Thông báo")
        End If
    End Sub
    Private Sub btnsavemk_Click(sender As System.Object, e As System.EventArgs) Handles btnsavemk.Click
        TestTextboxMK()
        If testdd = 1 Then
            Dim mamaykhoan As String = txtmamaykhoan.Text
            Dim tenmaykhoan As String = txttenmaykhoan.Text
            Dim dkmuikhoan As Single = Convert.ToSingle(txtdkmuikhoan.Text)
            Dim chieusaukhoantd As Single = Convert.ToSingle(txtchieusaukhoantd.Text)
            Dim huongkhoan As Single = Convert.ToSingle(txthuongkhoan.Text)
            maykhoan = New maykhoan(mamaykhoan, tenmaykhoan, dkmuikhoan, chieusaukhoantd, huongkhoan)
            bus = New knm2012BUS
            bus.InsertUpdateMK(maykhoan, flagmk)
            ClearBindingMK()
            LoadDataMayKhoan()
            LookButtonMK(False)
            txtmamaykhoan.Enabled = True
            LookDropButtonMK(True)
            dgvmaykhoan.RefreshDataSource()
            txtmamaykhoan.Enabled = True
        End If
    End Sub
    Private Function TestTextboxMK()
        If (Trim(txtmamaykhoan.Text) = "" Or Trim(txttenmaykhoan.Text) = "" Or Trim(txtdkmuikhoan.Text) = "" Or Trim(txthuongkhoan.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin, vui lòng kiểm tra lại!", MsgBoxStyle.Exclamation, "Thông báo")
            txtmadatda.Focus()
            testdd = 0
        ElseIf (CSng(txthuongkhoan.Text) < 0 Or CSng(txthuongkhoan.Text) > 90) Then
            MsgBox("Hướng khoan là góc nghiêng khi khoan với mặt phẳng thẳng đứng, nằm trong khoảng từ 0 đến 90 độ, vui lòng kiểm tra lại!", MsgBoxStyle.Exclamation, "Thông báo")
            testdd = 0
        Else
            testdd = 1
        End If
        Return testdd
    End Function
    Private Sub btncancelmk_Click(sender As System.Object, e As System.EventArgs) Handles btncancelmk.Click
        flagmk = 0
        txtmamaykhoan.Enabled = True
        ClearBindingMK()
        LoadDataMayKhoan()
        LookButtonMK(False)
        LookDropButtonMK(True)
        dgvmaykhoan.RefreshDataSource()
    End Sub
    Private Sub btnclosemk_Click(sender As System.Object, e As System.EventArgs) Handles btnclosemk.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#Region "tablokhoan"
    Dim flaglk As Integer = 0
    Dim testlk As Integer = 0
    Dim testcslk As Integer = 0
    Dim testcskt As Integer = 0
    Private Sub LoadDataLokhoan()
        dgvlokhoan.RefreshDataSource()
        bus = New knm2012BUS
        Dim lkList As New List(Of lokhoan)
        lkList = bus.GetDataLK()
        cm = Me.BindingContext(lkList)
        txtmalk.DataBindings.Add("Text", lkList, "MaLoKhoan")
        txtmact.DataBindings.Add("Text", lkList, "MaCongTruong")
        txtduongkinhlk.DataBindings.Add("Text", lkList, "Duongkinhlokhoan")
        txtchieucaotang.DataBindings.Add("Text", lkList, "Chieucaotang")
        txtchieusaulk.DataBindings.Add("Text", lkList, "Chieusaulokhoan")
        txtchieusaukt.DataBindings.Add("Text", lkList, "Chieusaukhoanthem")
        txtgocnghienglk.DataBindings.Add("Text", lkList, "Gocnghieng")
        txtchieucaocotnuoc.DataBindings.Add("Text", lkList, "Chieucaocotnuoc")
        txtghichulk.DataBindings.Add("Text", lkList, "Ghichu")
        dgvlokhoan.DataSource = lkList
    End Sub
    Private Sub LookButtonLK(ByVal l As Boolean)
        btnaddlk.Enabled = Not l
        btneditlk.Enabled = Not l
        btndeletelk.Enabled = Not l
        btnsavelk.Enabled = l
        btncancellk.Enabled = l
        btncloselk.Enabled = Not l
    End Sub
    Private Sub LookDropButtonLK(ByVal l As Boolean)
        editmalk.Enabled = Not l
        editmact.Enabled = Not l
        editduongkinhlk.Enabled = Not l
        editchieucaotang.Enabled = Not l
        editchieusaukt.Enabled = Not l
        editchieusaulk.Enabled = Not l
        editgocnghienglk.Enabled = Not l
        editchieucaocotnuoc.Enabled = Not l
    End Sub
    Private Sub ClearBindingLK()
        txtmalk.DataBindings.Clear()
        txtmact.DataBindings.Clear()
        txtghichulk.DataBindings.Clear()
        txtduongkinhlk.DataBindings.Clear()
        txtchieucaotang.DataBindings.Clear()
        txtchieusaukt.DataBindings.Clear()
        txtgocnghienglk.DataBindings.Clear()
        txtchieusaulk.DataBindings.Clear()
        txtchieucaocotnuoc.DataBindings.Clear()
    End Sub
    Private Sub ClearTextboxLK()
        txtmalk.Text = ""
        txtmact.Text = ""
        'txtghichulk.Text = ""
        txtduongkinhlk.Text = ""
        txtchieucaotang.Text = ""
        txtchieusaukt.Text = ""
        txtgocnghienglk.Text = ""
        txtchieusaulk.Text = ""
        'txtchieucaocotnuoc.Text = ""

    End Sub
    Private Sub editmalk_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmalk.TextChanged
        txtmalk.Text = editmalk.Text
    End Sub
    Private Sub editmact_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmact.TextChanged
        txtmact.Text = editmact.Text
    End Sub
    Private Sub editduongkinhlk_TextChanged(sender As System.Object, e As System.EventArgs) Handles editduongkinhlk.TextChanged
        txtduongkinhlk.Text = editduongkinhlk.Text
    End Sub

    Private Sub editchieucaotang_TextChanged(sender As System.Object, e As System.EventArgs) Handles editchieucaotang.TextChanged
        txtchieucaotang.Text = editchieucaotang.Text
    End Sub

    Private Sub editchieusaukt_TextChanged(sender As System.Object, e As System.EventArgs) Handles editchieusaukt.TextChanged
        txtchieusaukt.Text = editchieusaukt.Text
    End Sub

    Private Sub editgocnghienglk_TextChanged(sender As System.Object, e As System.EventArgs) Handles editgocnghienglk.TextChanged
        txtgocnghienglk.Text = editgocnghienglk.Text
    End Sub

    Private Sub editchieusaulk_TextChanged(sender As System.Object, e As System.EventArgs) Handles editchieusaulk.TextChanged
        txtchieusaulk.Text = editchieusaulk.Text
    End Sub

    Private Sub editchieucaocotnuoc_TextChanged(sender As System.Object, e As System.EventArgs) Handles editchieucaocotnuoc.TextChanged
        txtchieucaocotnuoc.Text = editchieucaocotnuoc.Text
    End Sub
    Private Function TestTextboxLK()
        If (Trim(txtmalk.Text) = "" Or Trim(txtduongkinhlk.Text) = "" Or Trim(txtchieucaotang.Text) = "" Or Trim(txtchieusaukt.Text) = "" Or Trim(txtgocnghienglk.Text) = "" Or Trim(txtchieusaulk.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin, vui lòng kiểm tra lại!", MsgBoxStyle.Exclamation, "Thông báo")
            txtmalk.Focus()
            testlk = 0
        ElseIf (CSng(txtgocnghienglk.Text) < 0 Or CSng(txtgocnghienglk.Text) > 90) Then
            MsgBox("Hướng khoan là góc nghiêng khi khoan với mặt phẳng thẳng đứng, nằm trong khoảng từ 0 đến 90 độ, vui lòng kiểm tra lại!", MsgBoxStyle.Exclamation, "Thông báo")
            txtgocnghienglk.Focus()
            testlk = 0
        ElseIf (CSng(txtduongkinhlk.Text) < 0 Or CSng(txtchieucaotang.Text) < 0 Or CSng(txtchieusaukt.Text) < 0 Or CSng(txtgocnghienglk.Text) < 0 Or CSng(txtchieusaulk.Text) < 0) Then
            MsgBox("Giá trị nhập vào phải lớn hơn 0, vui lòng kiểm tra lại", MsgBoxStyle.Exclamation, "Thông báo")
            testlk = 0
        Else
            testlk = 1
        End If
        Return testlk
    End Function
    Private Function TestChieusauKT()
        If ((CSng(txtchieusaukt.Text) < (0.01 * (CSng(txtduongkinhlk.Text)))) Or (CSng(txtchieusaukt.Text) > (0.015 * (CSng(txtduongkinhlk.Text))))) Then
            MsgBox("Giá trị của chiều sâu khoan thêm nằm trong khoảng 10dk đến 15dk, vui lòng kiểm tra lại", MsgBoxStyle.Exclamation, "Thông báo")
            testcskt = 0
        Else
            testcskt = 1
        End If
        Return testcskt
    End Function
    Private Function TestChieuSauLK()
        If ((CSng(txtchieusaulk.Text)) > (1 / (Sin(CSng(txtgocnghienglk.Text)))) * ((CSng(txtchieucaotang.Text)) + (CSng(txtchieusaukt.Text)))) Then
            MsgBox("Chiều sâu lỗ khoan phải nhỏ hơn chiều cao tầng + chiều sâu khoan thêm, vui lòng kiểm tra lại", MsgBoxStyle.Exclamation, "Thông báo")
            testcslk = 0
        Else
            testcslk = 1
        End If
        Return testcslk
    End Function
    Private Sub btnaddlk_Click(sender As System.Object, e As System.EventArgs) Handles btnaddlk.Click
        'ClearTextboxLK()
        flaglk = 1
        LookButtonLK(True)
        LookDropButtonLK(False)
        txtmalk.Focus()
    End Sub
    Private Sub btneditlk_Click(sender As System.Object, e As System.EventArgs) Handles btneditlk.Click
        flaglk = 2
        LookButtonLK(True)
        LookDropButtonLK(False)
        txtduongkinhlk.Focus()
        txtmalk.Enabled = False
        editmalk.Enabled = False
    End Sub
    Private Sub btndeletelk_Click(sender As System.Object, e As System.EventArgs) Handles btndeletelk.Click
        Dim malokhoan As String = txtmalk.Text
        Dim mact As String = txtmact.Text
        Dim ghichu As String = txtghichulk.Text
        Dim duongkinhlk As Single = Convert.ToSingle(txtduongkinhlk.Text)
        Dim chieucaotang As Single = Convert.ToSingle(txtchieucaotang.Text)
        Dim chieusaukt As Single = Convert.ToSingle(txtchieusaukt.Text)
        Dim gocnghienglk As Single = Convert.ToSingle(txtgocnghienglk.Text)
        Dim chieusaulk As Single = Convert.ToSingle(txtchieusaulk.Text)
        Dim chieucaocotnuoc As Single = Convert.ToSingle(txtchieucaocotnuoc.Text)
        lokhoan = New lokhoan(malokhoan, mact, ghichu, duongkinhlk, chieucaotang, chieusaukt, gocnghienglk, chieusaulk, chieucaocotnuoc)
        Dim bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
            bus.DeleteLK(lokhoan)
            ClearBindingLK()
            LoadDataLokhoan()
            LookButtonLK(False)
            LookDropButtonLK(True)
            MsgBox("Bạn đã xóa thành công!", MsgBoxStyle.Information, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa!", MsgBoxStyle.Information, "Thông báo")
        End If
    End Sub
    Private Sub btnsavelk_Click(sender As System.Object, e As System.EventArgs) Handles btnsavelk.Click
        TestTextboxLK()
        TestChieuSauLK()
        TestChieusauKT()
        If (testlk = 1 And testcslk = 1 And testcskt = 1) Then
            Dim malokhoan As String = txtmalk.Text
            Dim mact As String = txtmact.Text
            Dim ghichu As String = txtghichulk.Text
            Dim duongkinhlk As Single = Convert.ToSingle(txtduongkinhlk.Text)
            Dim chieucaotang As Single = Convert.ToSingle(txtchieucaotang.Text)
            Dim chieusaukt As Single = Convert.ToSingle(txtchieusaukt.Text)
            Dim gocnghienglk As Single = Convert.ToSingle(txtgocnghienglk.Text)
            Dim chieusaulk As Single = Convert.ToSingle(txtchieusaulk.Text)
            Dim chieucaocotnuoc As Single = Convert.ToSingle(txtchieucaocotnuoc.Text)
            lokhoan = New lokhoan(malokhoan, mact, ghichu, chieucaotang, duongkinhlk, chieusaukt, chieusaulk, chieucaocotnuoc, gocnghienglk)
            Dim bus = New knm2012BUS
            bus.InsertUpdateLK(lokhoan, flaglk)
            ClearBindingLK()
            LoadDataLokhoan()
            LookButtonLK(False)
            LookDropButtonLK(True)
            dgvlokhoan.RefreshDataSource()
            txtmalk.Enabled = True
        End If
    End Sub
    Private Sub btncancellk_Click(sender As System.Object, e As System.EventArgs) Handles btncancellk.Click
        flaglk = 0
        txtmalk.Enabled = True
        ClearBindingLK()
        LoadDataLokhoan()
        LookButtonLK(False)
        LookDropButtonLK(True)
        dgvlokhoan.RefreshDataSource()
    End Sub
    Private Sub btncloselk_Click(sender As System.Object, e As System.EventArgs) Handles btncloselk.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#Region "tabthuocno"
    Dim flagtn, testtn As Integer
    Private Sub LoadDataThuocNo()
        dgvthuocno.RefreshDataSource()
        bus = New knm2012BUS
        Dim tnList As New List(Of thuocno)
        tnList = bus.GetDaTaTN()
        cm = Me.BindingContext(tnList)
        txtmathuocno.DataBindings.Add("Text", tnList, "Mathuocno")
        txttenthuocno.DataBindings.Add("Text", tnList, "Tenthuocno")
        txttocdono.DataBindings.Add("Text", tnList, "Tocdono")
        txtknsinhcong.DataBindings.Add("Text", tnList, "Khanangsinhcong")
        txtknchiunuoc.DataBindings.Add("Text", tnList, "Khanangchiunuoc")
        txthschuyendoi.DataBindings.Add("Text", tnList, "Hesochuyendoi")
        txtdonvitinh.DataBindings.Add("Text", tnList, "Donvitinh")
        txtgiathanh.DataBindings.Add("Text", tnList, "GiaThanh")
        dgvthuocno.DataSource = tnList
    End Sub
    Private Sub LookButtonTN(ByVal l As Boolean)
        btnaddtn.Enabled = Not l
        btnedittn.Enabled = Not l
        btndeletetn.Enabled = Not l
        btnsavetn.Enabled = l
        btncanceltn.Enabled = l
        btnclosetn.Enabled = Not l
    End Sub
    Private Sub LookDropButtonTN(ByVal l As Boolean)
        editmathuocno.Enabled = Not l
        edittenthuocno.Enabled = Not l
        edittocdono.Enabled = Not l
        editkhanangsinhcong.Enabled = Not l
        editkhanangchiunuoc.Enabled = Not l
        edithesochuyendoi.Enabled = Not l
        editdonvitinh.Enabled = Not l
        editgiathanh.Enabled = Not l
    End Sub
    Private Function TestTextboxTN()
        If (Trim(txtmathuocno.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin", MsgBoxStyle.Exclamation, "Thông báo")
            testtn = 0
        Else
            testtn = 1
        End If
        Return testtn
    End Function
    Private Sub ClearBindingTN()
        txtmathuocno.DataBindings.Clear()
        txttenthuocno.DataBindings.Clear()
        txttocdono.DataBindings.Clear()
        txtknsinhcong.DataBindings.Clear()
        txtknchiunuoc.DataBindings.Clear()
        txthschuyendoi.DataBindings.Clear()
        txtdonvitinh.DataBindings.Clear()
        txtgiathanh.DataBindings.Clear()
    End Sub
    Private Sub ClearTextboxTN()
        txtmathuocno.Text = ""
        txttenthuocno.Text = ""
        txttocdono.Text = ""
        txtknsinhcong.Text = ""
        txtknchiunuoc.Text = ""
        txthschuyendoi.Text = ""
        txtdonvitinh.Text = ""
        txtgiathanh.Text = ""
    End Sub
    Private Sub editmathuocno_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmathuocno.TextChanged
        txtmathuocno.Text = editmathuocno.Text
    End Sub
    Private Sub edittenthuocno_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittenthuocno.TextChanged
        txttenthuocno.Text = edittenthuocno.Text
    End Sub
    Private Sub edittocdono_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittocdono.TextChanged
        txttocdono.Text = edittocdono.Text
    End Sub
    Private Sub editkhanangsinhcong_TextChanged(sender As System.Object, e As System.EventArgs) Handles editkhanangsinhcong.TextChanged
        txtknsinhcong.Text = editkhanangsinhcong.Text
    End Sub
    Private Sub editkhanangchiunuoc_TextChanged(sender As System.Object, e As System.EventArgs) Handles editkhanangchiunuoc.TextChanged
        txtknchiunuoc.Text = editkhanangchiunuoc.Text
    End Sub
    Private Sub edithesochuyendoi_TextChanged(sender As System.Object, e As System.EventArgs) Handles edithesochuyendoi.TextChanged
        txthschuyendoi.Text = edithesochuyendoi.Text
    End Sub
    Private Sub editdonvitinh_TextChanged(sender As System.Object, e As System.EventArgs) Handles editdonvitinh.TextChanged
        txtdonvitinh.Text = editdonvitinh.Text
    End Sub
    Private Sub editgiathanh_TextChanged(sender As System.Object, e As System.EventArgs) Handles editgiathanh.TextChanged
        txtgiathanh.Text = editgiathanh.Text
    End Sub
    Private Sub btnaddtn_Click(sender As System.Object, e As System.EventArgs) Handles btnaddtn.Click
        flagtn = 1
        ClearBindingTN()
        ClearTextboxTN()
        LookButtonTN(True)
        LookDropButtonTN(False)
        txtmathuocno.Focus()
        txtmathuocno.Enabled = True
    End Sub
    Private Sub btnedittn_Click(sender As System.Object, e As System.EventArgs) Handles btnedittn.Click
        flagtn = 2
        LookButtonTN(True)
        LookDropButtonTN(False)
        txttenthuocno.Focus()
        txtmathuocno.Enabled = False
        editmathuocno.Enabled = False
    End Sub
    Private Sub btndeletetn_Click(sender As System.Object, e As System.EventArgs) Handles btndeletetn.Click
        Dim mathuocno As String = txtmathuocno.Text
        Dim tenthuocno As String = txttenthuocno.Text
        Dim khanangsinhcong As String = txtknsinhcong.Text
        Dim tocdono As String = txttocdono.Text
        Dim khanangchiunuoc As String = txtknchiunuoc.Text
        Dim hesochuyendoi As String = txthschuyendoi.Text
        Dim donvitinh As String = txtdonvitinh.Text
        Dim giathanh As Single = Convert.ToSingle(txtgiathanh.Text)
        thuocno = New thuocno(mathuocno, tenthuocno, tocdono, khanangsinhcong, khanangchiunuoc, hesochuyendoi, donvitinh, giathanh)
        bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) = Windows.Forms.DialogResult.Yes Then
            bus.DeleteTN(thuocno)
            ClearBindingTN()
            LoadDataThuocNo()
            LookButtonTN(False)
            LookDropButtonTN(True)
            dgvthuocno.RefreshDataSource()
            MsgBox("Bạn đã xóa thành công", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa", MsgBoxStyle.Exclamation, "Thông báo")
        End If
    End Sub

    Private Sub btnsavetn_Click(sender As System.Object, e As System.EventArgs) Handles btnsavetn.Click
        TestTextboxTN()
        If testtn = 1 Then
            Dim mathuocno As String = txtmathuocno.Text
            Dim tenthuocno As String = txttenthuocno.Text
            Dim khanangsinhcong As String = txtknsinhcong.Text
            Dim tocdono As String = txttocdono.Text
            Dim khanangchiunuoc As String = txtknchiunuoc.Text
            Dim hesochuyendoi As String = txthschuyendoi.Text
            Dim donvitinh As String = txtdonvitinh.Text
            Dim giathanh As Single = Convert.ToSingle(txtgiathanh.Text)
            thuocno = New thuocno(mathuocno, tenthuocno, tocdono, khanangsinhcong, khanangchiunuoc, hesochuyendoi, donvitinh, giathanh)
            bus = New knm2012BUS
            bus.InsertUpdateTN(thuocno, flagtn)
            ClearBindingTN()
            LoadDataThuocNo()
            LookButtonTN(False)
            LookDropButtonTN(True)
            dgvthuocno.RefreshDataSource()
            txtmathuocno.Enabled = True
        End If
    End Sub
    Private Sub btncanceltn_Click(sender As System.Object, e As System.EventArgs) Handles btncanceltn.Click
        flagtn = 0
        ClearBindingTN()
        LoadDataThuocNo()
        LookButtonTN(False)
        LookDropButtonTN(True)
        dgvthuocno.RefreshDataSource()
        txtmathuocno.Enabled = True
    End Sub
    Private Sub btnclosetn_Click(sender As System.Object, e As System.EventArgs) Handles btnclosetn.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#Region "tabkipno"
    Dim flagkn, testkn As Integer
    Private Sub LoadDataKipNo()
        dgvkipno.RefreshDataSource()
        bus = New knm2012BUS
        Dim knList As New List(Of kipno)
        knList = bus.GetDaTaKN()
        cm = Me.BindingContext(knList)
        txtmakipno.DataBindings.Add("Text", knList, "Makipno")
        txttenkipno.DataBindings.Add("Text", knList, "Tenkipno")
        txtthoigianvisai.DataBindings.Add("Text", knList, "Thoigianvisai")
        txtduongkinhkip.DataBindings.Add("Text", knList, "Duongkinhkip")
        txtchieudaikip.DataBindings.Add("Text", knList, "Chieudaikip")
        txtdvtinhkip.DataBindings.Add("Text", knList, "Donvitinh")
        txtgiakip.DataBindings.Add("Text", knList, "Giathanh")
        dgvkipno.DataSource = knList
    End Sub
    Private Sub LookButtonKN(ByVal l As Boolean)
        btnaddkip.Enabled = Not l
        btneditkip.Enabled = Not l
        btndeletekip.Enabled = Not l
        btnsavekip.Enabled = l
        btncancelkip.Enabled = l
        btnclosekip.Enabled = Not l
    End Sub
    Private Sub LookDropButtonKN(ByVal l As Boolean)
        editmakipno.Enabled = Not l
        edittenkipno.Enabled = Not l
        editthoigianvisai.Enabled = Not l
        editduongkinhkip.Enabled = Not l
        editchieudaikip.Enabled = Not l
        editdvtinhkip.Enabled = Not l
        editgiakip.Enabled = Not l
    End Sub
    Private Function TestTextboxKN()
        If (Trim(txtmakipno.Text) = "" Or Trim(txttenkipno.Text) = "" Or Trim(txtduongkinhkip.Text) = "" Or Trim(txtchieudaikip.Text) = "" Or Trim(txtdvtinhkip.Text) = "" Or Trim(txtgiakip.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin", MsgBoxStyle.Exclamation, "Thông báo")
            testkn = 0
        Else
            testkn = 1
        End If
        Return testkn
    End Function
    Private Sub ClearBindingKN()
        txtmakipno.DataBindings.Clear()
        txttenkipno.DataBindings.Clear()
        txtduongkinhkip.DataBindings.Clear()
        txtthoigianvisai.DataBindings.Clear()
        txtchieudaikip.DataBindings.Clear()
        txtdvtinhkip.DataBindings.Clear()
        txtgiakip.DataBindings.Clear()
    End Sub
    Private Sub ClearTextboxKN()
        txtmakipno.Text = ""
        txttenkipno.Text = ""
        txtthoigianvisai.Text = ""
        txtduongkinhkip.Text = ""
        txtchieudaikip.Text = ""
        txtdvtinhkip.Text = ""
        txtgiakip.Text = ""
    End Sub
    Private Sub editmakipno_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmakipno.TextChanged
        txtmakipno.Text = editmakipno.Text
    End Sub
    Private Sub edittenkipno_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittenkipno.TextChanged
        txttenkipno.Text = edittenkipno.Text
    End Sub
    Private Sub editthoigianvisai_TextChanged(sender As System.Object, e As System.EventArgs) Handles editthoigianvisai.TextChanged
        txtthoigianvisai.Text = editthoigianvisai.Text
    End Sub
    Private Sub editduongkinhkip_TextChanged(sender As System.Object, e As System.EventArgs) Handles editduongkinhkip.TextChanged
        txtduongkinhkip.Text = editduongkinhkip.Text
    End Sub
    Private Sub editchieudaikip_TextChanged(sender As System.Object, e As System.EventArgs) Handles editchieudaikip.TextChanged
        txtchieudaikip.Text = editchieudaikip.Text
    End Sub
    Private Sub editdvtinhkip_TextChanged(sender As System.Object, e As System.EventArgs) Handles editdvtinhkip.TextChanged
        txtdvtinhkip.Text = editdvtinhkip.Text
    End Sub
    Private Sub editgiakip_TextChanged(sender As System.Object, e As System.EventArgs) Handles editgiakip.TextChanged
        txtgiakip.Text = editgiakip.Text
    End Sub
    Private Sub btnaddkip_Click(sender As System.Object, e As System.EventArgs) Handles btnaddkip.Click
        flagkn = 1
        ClearBindingKN()
        ClearTextboxKN()
        LookButtonKN(True)
        LookDropButtonKN(False)
        txtmakipno.Focus()
        txtmakipno.Enabled = True
    End Sub
    Private Sub btneditkip_Click(sender As System.Object, e As System.EventArgs) Handles btneditkip.Click
        flagkn = 2
        LookButtonKN(True)
        LookDropButtonKN(False)
        txttenkipno.Focus()
        txtmakipno.Enabled = False
        editmakipno.Enabled = False
    End Sub
    Private Sub btndeletekip_Click(sender As System.Object, e As System.EventArgs) Handles btndeletekip.Click
        Dim makipno As String = txtmakipno.Text
        Dim tenkipno As String = txttenkipno.Text '
        Dim thoigianvisai As Single = Convert.ToSingle(txtthoigianvisai.Text)
        Dim duongkinhkip As Single = Convert.ToSingle(txtduongkinhkip.Text)
        Dim chieudaikip As Single = Convert.ToSingle(txtchieudaikip.Text)
        Dim donvitinh As String = txtdvtinhkip.Text
        Dim giathanh As Single = Convert.ToSingle(txtgiakip.Text)
        kipno = New kipno(makipno, tenkipno, thoigianvisai, duongkinhkip, chieudaikip, donvitinh, giathanh)
        bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) = Windows.Forms.DialogResult.Yes Then
            bus.DeleteKN(kipno)
            ClearBindingKN()
            LoadDataKipNo()
            LookButtonKN(False)
            LookDropButtonKN(True)
            dgvkipno.RefreshDataSource()
            MsgBox("Bạn đã xóa thành công", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa", MsgBoxStyle.Exclamation, "Thông báo")
        End If
    End Sub

    Private Sub btnsavekip_Click(sender As System.Object, e As System.EventArgs) Handles btnsavekip.Click
        TestTextboxKN()
        If testkn = 1 Then
            Dim makipno As String = txtmakipno.Text
            Dim tenkipno As String = txttenkipno.Text
            Dim thoigianvisai As Single = Convert.ToSingle(txtthoigianvisai.Text)
            Dim duongkinhkip As Single = Convert.ToSingle(txtduongkinhkip.Text)
            Dim chieudaikip As Single = Convert.ToSingle(txtchieudaikip.Text)
            Dim donvitinh As String = txtdvtinhkip.Text
            Dim giathanh As Single = Convert.ToSingle(txtgiakip.Text)
            kipno = New kipno(makipno, tenkipno, thoigianvisai, duongkinhkip, chieudaikip, donvitinh, giathanh)
            bus = New knm2012BUS
            bus.InsertUpdateKN(kipno, flagkn)
            ClearBindingKN()
            LoadDataKipNo()
            LookButtonKN(False)
            LookDropButtonKN(True)
            dgvkipno.RefreshDataSource()
            txtmakipno.Enabled = True
        End If
    End Sub
    Private Sub btncancelkip_Click(sender As System.Object, e As System.EventArgs) Handles btncancelkip.Click
        flagkn = 0
        ClearBindingKN()
        LoadDataKipNo()
        LookButtonKN(False)
        LookDropButtonKN(True)
        dgvkipno.RefreshDataSource()
        txtmakipno.Enabled = True
    End Sub
    Private Sub btnclosekip_Click(sender As System.Object, e As System.EventArgs) Handles btnclosekip.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#Region "tabdayno"
    Dim flagdn, testdn As Integer
    Private Sub LoadDataDayNo()
        dgvdayno.RefreshDataSource()
        bus = New knm2012BUS
        Dim dnList As New List(Of dayno)
        dnList = bus.GetDaTaDN()
        cm = Me.BindingContext(dnList)
        txtmadayno.DataBindings.Add("Text", dnList, "Madayno")
        txttendayno.DataBindings.Add("Text", dnList, "Tendayno")
        txtdkngoai.DataBindings.Add("Text", dnList, "Duongkinhngoai")
        txtmatdothuoc.DataBindings.Add("Text", dnList, "Matdothuoc")
        txttocdonoday.DataBindings.Add("Text", dnList, "Tocdono")
        txtknchiunuocday.DataBindings.Add("Text", dnList, "Khanangchiunuoc")
        txtknchiunhietday.DataBindings.Add("Text", dnList, "Khanangchiunhiet")
        txtdvtinhday.DataBindings.Add("Text", dnList, "Donvitinh")
        txtgiaday.DataBindings.Add("Text", dnList, "Giathanh")
        dgvdayno.DataSource = dnList
    End Sub
    Private Sub LookButtonDN(ByVal l As Boolean)
        btnadddn.Enabled = Not l
        btneditdn.Enabled = Not l
        btndeletedn.Enabled = Not l
        btnsavedn.Enabled = l
        btncanceldn.Enabled = l
        btnclosedn.Enabled = Not l
    End Sub
    Private Sub LookDropButtonDN(ByVal l As Boolean)
        editmadayno.Enabled = Not l
        edittendayno.Enabled = Not l
        edittocdonoday.Enabled = Not l
        editmatdothuoc.Enabled = Not l
        editdkngoai.Enabled = Not l
        editknchiunhietday.Enabled = Not l
        editknchiunuocday.Enabled = Not l
        editdvtinhday.Enabled = Not l
        editgiaday.Enabled = Not l
    End Sub
    Private Function TestTextboxDN()
        If (Trim(txtmadayno.Text) = "" Or Trim(txttendayno.Text) = "" Or Trim(txttocdonoday.Text) = "" Or Trim(txtmatdothuoc.Text) = "" Or Trim(txtdkngoai.Text) = "" Or Trim(txtknchiunhietday.Text) = "" Or Trim(txtknchiunuocday.Text) = "" Or Trim(txtdvtinhday.Text) = "" Or Trim(txtgiaday.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin", MsgBoxStyle.Exclamation, "Thông báo")
            testdn = 0
        Else
            testdn = 1
        End If
        Return testdn
    End Function
    Private Sub ClearBindingDN()
        txtmadayno.DataBindings.Clear()
        txttendayno.DataBindings.Clear()
        txtdkngoai.DataBindings.Clear()
        txttocdonoday.DataBindings.Clear()
        txtmatdothuoc.DataBindings.Clear()
        txtknchiunuocday.DataBindings.Clear()
        txtknchiunhietday.DataBindings.Clear()
        txtdvtinhday.DataBindings.Clear()
        txtgiaday.DataBindings.Clear()
    End Sub
    Private Sub ClearTextboxDN()
        txtmadayno.Text = ""
        txttendayno.Text = ""
        txtdkngoai.Text = ""
        txttocdonoday.Text = ""
        txtmatdothuoc.Text = ""
        txtknchiunuocday.Text = ""
        txtknchiunhietday.Text = ""
        txtdvtinhday.Text = ""
        txtgiaday.Text = ""
    End Sub
    Private Sub editmadayno_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmadayno.TextChanged
        txtmadayno.Text = editmadayno.Text
    End Sub
    Private Sub edittendayno_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittendayno.TextChanged
        txttendayno.Text = edittendayno.Text
    End Sub
    Private Sub editdkngoai_TextChanged(sender As System.Object, e As System.EventArgs) Handles editdkngoai.TextChanged
        txtdkngoai.Text = editdkngoai.Text
    End Sub
    Private Sub edittocdonoday_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittocdonoday.TextChanged
        txttocdono.Text = edittocdono.Text
    End Sub
    Private Sub editmatdothuoc_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmatdothuoc.TextChanged
        txtmatdothuoc.Text = editmatdothuoc.Text
    End Sub
    Private Sub editknchiunuocday_TextChanged(sender As System.Object, e As System.EventArgs) Handles editknchiunuocday.TextChanged
        txtknchiunuocday.Text = editknchiunuocday.Text
    End Sub
    Private Sub editknchiunhietday_TextChanged(sender As System.Object, e As System.EventArgs) Handles editknchiunhietday.TextChanged
        txtknchiunhietday.Text = editknchiunhietday.Text
    End Sub
    Private Sub editdvtinhday_TextChanged(sender As System.Object, e As System.EventArgs) Handles editdvtinhday.TextChanged
        txtdvtinhday.Text = editdvtinhday.Text
    End Sub
    Private Sub editgiaday_TextChanged(sender As System.Object, e As System.EventArgs) Handles editgiaday.TextChanged
        txtgiaday.Text = editgiaday.Text
    End Sub
    Private Sub btnadddn_Click(sender As System.Object, e As System.EventArgs) Handles btnadddn.Click
        flagdn = 1
        ClearBindingDN()
        ClearTextboxDN()
        LookButtonDN(True)
        LookDropButtonDN(False)
        txtmadayno.Focus()
        txtmadayno.Enabled = True
    End Sub
    Private Sub btneditdn_Click(sender As System.Object, e As System.EventArgs) Handles btneditdn.Click
        flagdn = 2
        LookButtonDN(True)
        LookDropButtonDN(False)
        txttendayno.Focus()
        txtmadayno.Enabled = False
        editmadayno.Enabled = False
    End Sub
    Private Sub btndeletedn_Click(sender As System.Object, e As System.EventArgs) Handles btndeletedn.Click
        Dim madayno As String = txtmadayno.Text
        Dim tendayno As String = txttendayno.Text
        Dim duongkinhngoai As String = txtdkngoai.Text
        Dim matdothuoc As Single = Convert.ToSingle(txtmatdothuoc.Text)
        Dim tocdono As String = txttocdono.Text
        Dim knchiunuoc As String = txtknchiunuocday.Text
        Dim knchiunhiet As String = txtknchiunhietday.Text
        Dim dvtinh As String = txtdvtinhday.Text
        Dim giathanh As Single = Convert.ToSingle(txtgiaday.Text)
        dayno = New dayno(madayno, tendayno, duongkinhngoai, matdothuoc, tocdono, knchiunhiet, knchiunuoc, dvtinh, giathanh)
        bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) = Windows.Forms.DialogResult.Yes Then
            bus.DeleteDN(dayno)
            ClearBindingDN()
            LoadDataDayNo()
            LookButtonDN(False)
            LookDropButtonDN(True)
            dgvdayno.RefreshDataSource()
            MsgBox("Bạn đã xóa thành công", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa", MsgBoxStyle.Exclamation, "Thông báo")
        End If
    End Sub

    Private Sub btnsavedn_Click(sender As System.Object, e As System.EventArgs) Handles btnsavedn.Click
        TestTextboxDN()
        If testdn = 1 Then
            Dim madayno As String = txtmadayno.Text
            Dim tendayno As String = txttendayno.Text
            Dim duongkinhngoai As String = txtdkngoai.Text
            Dim matdothuoc As Single = Convert.ToSingle(txtmatdothuoc.Text)
            Dim tocdono As String = txttocdono.Text
            Dim knchiunuoc As String = txtknchiunuocday.Text
            Dim knchiunhiet As String = txtknchiunhietday.Text
            Dim dvtinh As String = txtdvtinhday.Text
            Dim giathanh As Single = Convert.ToSingle(txtgiaday.Text)
            dayno = New dayno(madayno, tendayno, duongkinhngoai, matdothuoc, tocdono, knchiunhiet, knchiunuoc, dvtinh, giathanh)
            bus = New knm2012BUS
            bus.InsertUpdateDN(dayno, flagdn)
            ClearBindingDN()
            LoadDataDayNo()
            LookButtonDN(False)
            LookDropButtonDN(True)
            dgvdayno.RefreshDataSource()
            txtmadayno.Enabled = True
        End If
    End Sub
    Private Sub btncanceldn_Click(sender As System.Object, e As System.EventArgs) Handles btncanceldn.Click
        flagdn = 0
        ClearBindingDN()
        LoadDataDayNo()
        LookButtonDN(False)
        LookDropButtonDN(True)
        dgvdayno.RefreshDataSource()
        txtmadayno.Enabled = True
    End Sub
    Private Sub btnclosedn_Click(sender As System.Object, e As System.EventArgs) Handles btnclosedn.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#Region "tabmaynomin"
    Dim flagmn, testmn As Integer
    Private Sub LoadDataMayNo()
        dgvmayno.RefreshDataSource()
        bus = New knm2012BUS
        Dim mnList As New List(Of maynomin)
        mnList = bus.GetDataMN()
        cm = Me.BindingContext(mnList)
        txtmamayno.DataBindings.Add("Text", mnList, "Mamayno")
        txttenmayno.DataBindings.Add("Text", mnList, "Tenmayno")
        dgvmayno.DataSource = mnList
    End Sub
    Private Sub LookButtonMN(ByVal l As Boolean)
        btnaddmn.Enabled = Not l
        btneditmn.Enabled = Not l
        btndeletemn.Enabled = Not l
        btnsavemn.Enabled = l
        btncancelmn.Enabled = l
        btnclosemn.Enabled = Not l
    End Sub
    Private Sub LookDropButtonMN(ByVal l As Boolean)
        editmamayno.Enabled = Not l
        edittenmayno.Enabled = Not l
    End Sub
    Private Function TestTextboxMN()
        If (Trim(txtmamayno.Text) = "" Or Trim(txttenmayno.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin", MsgBoxStyle.Exclamation, "Thông báo")
            testmn = 0
        Else
            testmn = 1
        End If
        Return testmn
    End Function
    Private Sub ClearBindingMN()
        txtmamayno.DataBindings.Clear()
        txttenmayno.DataBindings.Clear()
    End Sub
    Private Sub ClearTextboxMN()
        txtmamayno.Text = ""
        txttenmayno.Text = ""
    End Sub
    Private Sub editmamayno_TextChange(sender As System.Object, e As System.EventArgs) Handles editmamayno.TextChanged
        txtmamayno.Text = editmamayno.Text
    End Sub
    Private Sub edittenmayno_TextChange(sender As System.Object, e As System.EventArgs) Handles edittenmayno.TextChanged
        txttendayno.Text = edittendayno.Text
    End Sub
    Private Sub btnaddmn_Click(sender As System.Object, e As System.EventArgs) Handles btnaddmn.Click
        flagmn = 1
        ClearBindingMN()
        ClearTextboxMN()
        LookButtonMN(True)
        LookDropButtonMN(False)
        txtmamayno.Focus()
        txtmamayno.Enabled = True
    End Sub
    Private Sub btneditmn_Click(sender As System.Object, e As System.EventArgs) Handles btneditmn.Click
        flagmn = 2
        LookButtonMN(True)
        LookDropButtonMN(False)
        txttenmayno.Focus()
        txtmamayno.Enabled = False
        editmamayno.Enabled = False
    End Sub
    Private Sub btndeletemn_Click(sender As System.Object, e As System.EventArgs) Handles btndeletemn.Click
        Dim mamayno As String = txtmamayno.Text
        Dim tenmayno As String = txttenmayno.Text
        maynomin = New maynomin(mamayno, tenmayno)
        bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) = Windows.Forms.DialogResult.Yes Then
            bus.DeleteMN(maynomin)
            ClearBindingMN()
            LoadDataMayNo()
            LookButtonMN(False)
            LookDropButtonMN(True)
            dgvmayno.RefreshDataSource()
            MsgBox("Bạn đã xóa thành công", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa", MsgBoxStyle.Exclamation, "Thông báo")
        End If
    End Sub

    Private Sub btnsavemn_Click(sender As System.Object, e As System.EventArgs) Handles btnsavemn.Click
        TestTextboxMN()
        If testmn = 1 Then
            Dim mamayno As String = txtmamayno.Text
            Dim tenmayno As String = txttenmayno.Text
            maynomin = New maynomin(mamayno, tenmayno)
            bus = New knm2012BUS
            bus.InsertUpdateMN(maynomin, flagmn)
            ClearBindingMN()
            LoadDataMayNo()
            LookButtonMN(False)
            LookDropButtonMN(True)
            dgvmayno.RefreshDataSource()
            txtmamayno.Enabled = True
        End If
    End Sub
    Private Sub btncancelmn_Click(sender As System.Object, e As System.EventArgs) Handles btncancelmn.Click
        flagmn = 0
        ClearBindingMN()
        LoadDataMayNo()
        LookButtonMN(False)
        LookDropButtonMN(True)
        dgvmayno.RefreshDataSource()
        txtmamayno.Enabled = True
    End Sub
    Private Sub btnclosemn_Click(sender As System.Object, e As System.EventArgs) Handles btnclosemn.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#Region "tabppno"
    Dim flagppn, testppn As Integer
    Private Sub LoadDataPPNo()
        dgvppno.RefreshDataSource()
        bus = New knm2012BUS
        Dim ppnList As New List(Of phuongphapno)
        ppnList = bus.GetDataPPN()
        cm = Me.BindingContext(ppnList)
        txtmappn.DataBindings.Add("Text", ppnList, "Mappn")
        txttenppn.DataBindings.Add("Text", ppnList, "Tenppn")
        dgvppno.DataSource = ppnList
    End Sub
    Private Sub LookButtonPPN(ByVal l As Boolean)
        btnaddppn.Enabled = Not l
        btneditppn.Enabled = Not l
        btndeleteppn.Enabled = Not l
        btnsaveppn.Enabled = l
        btncancelppn.Enabled = l
        btncloseppn.Enabled = Not l
    End Sub
    Private Sub LookDropButtonPPN(ByVal l As Boolean)
        editmappn.Enabled = Not l
        edittenppn.Enabled = Not l
    End Sub
    Private Function TestTextboxPPN()
        If (Trim(txtmappn.Text) = "" Or Trim(txttenppn.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin", MsgBoxStyle.Exclamation, "Thông báo")
            testppn = 0
        Else
            testppn = 1
        End If
        Return testppn
    End Function
    Private Sub ClearBindingPPN()
        txtmappn.DataBindings.Clear()
        txttenppn.DataBindings.Clear()
    End Sub
    Private Sub ClearTextboxPPN()
        txtmappn.Text = ""
        txttenppn.Text = ""
    End Sub
    Private Sub editmappn_TextChange(sender As System.Object, e As System.EventArgs) Handles editmappn.TextChanged
        txtmappn.Text = editmappn.Text
    End Sub
    Private Sub edittenppn_TextChange(sender As System.Object, e As System.EventArgs) Handles edittenppn.TextChanged
        txttenppn.Text = edittenppn.Text
    End Sub
    Private Sub btnaddppn_Click(sender As System.Object, e As System.EventArgs) Handles btnaddppn.Click
        flagppn = 1
        ClearBindingPPN()
        ClearTextboxPPN()
        LookButtonPPN(True)
        LookDropButtonPPN(False)
        txtmappn.Focus()
        txtmappn.Enabled = True
    End Sub
    Private Sub btneditppn_Click(sender As System.Object, e As System.EventArgs) Handles btneditppn.Click
        flagppn = 2
        LookButtonPPN(True)
        LookDropButtonPPN(False)
        txttenppn.Focus()
        txtmappn.Enabled = False
        editmappn.Enabled = False
    End Sub
    Private Sub btndeleteppn_Click(sender As System.Object, e As System.EventArgs) Handles btndeleteppn.Click
        Dim mappn As String = txtmappn.Text
        Dim tenppn As String = txttenppn.Text
        ppno = New phuongphapno(mappn, tenppn)
        bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) = Windows.Forms.DialogResult.Yes Then
            bus.DeletePPN(ppno)
            ClearBindingPPN()
            LoadDataPPNo()
            LookButtonPPN(False)
            LookDropButtonPPN(True)
            dgvppno.RefreshDataSource()
            MsgBox("Bạn đã xóa thành công", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa", MsgBoxStyle.Exclamation, "Thông báo")
        End If
    End Sub

    Private Sub btnsaveppn_Click(sender As System.Object, e As System.EventArgs) Handles btnsaveppn.Click
        TestTextboxPPN()
        If testppn = 1 Then
            Dim mappn As String = txtmappn.Text
            Dim tenppn As String = txttenppn.Text
            ppno = New phuongphapno(mappn, tenppn)
            bus = New knm2012BUS
            bus.InsertUpdatePPN(ppno, flagppn)
            ClearBindingPPN()
            LoadDataPPNo()
            LookButtonPPN(False)
            LookDropButtonPPN(True)
            dgvppno.RefreshDataSource()
            txtmappn.Enabled = True
        End If
    End Sub
    Private Sub btncancelppn_Click(sender As System.Object, e As System.EventArgs) Handles btncancelppn.Click
        flagppn = 0
        ClearBindingPPN()
        LoadDataPPNo()
        LookButtonPPN(False)
        LookDropButtonPPN(True)
        dgvppno.RefreshDataSource()
        txtmappn.Enabled = True
    End Sub
    Private Sub btncloseppn_Click(sender As System.Object, e As System.EventArgs) Handles btncloseppn.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#Region "tabphukienno"
    Dim flagpk, testpk As Integer
    Private Sub LoadDataPKNo()
        dgvpkno.RefreshDataSource()
        bus = New knm2012BUS
        Dim pkList As New List(Of phukienno)
        pkList = bus.GetDataPK()
        cm = Me.BindingContext(pkList)
        txtmapk.DataBindings.Add("Text", pkList, "Mapk")
        txttenpk.DataBindings.Add("Text", pkList, "Tenpk")
        txtdvtinhpk.DataBindings.Add("Text", pkList, "Donvitinh")
        txtgiapk.DataBindings.Add("Text", pkList, "Giathanh")
        dgvpkno.DataSource = pkList
    End Sub
    Private Sub LookButtonPK(ByVal l As Boolean)
        btnaddpk.Enabled = Not l
        btneditpk.Enabled = Not l
        btndeletepk.Enabled = Not l
        btnsavepk.Enabled = l
        btncancelpk.Enabled = l
        btnclosepk.Enabled = Not l
    End Sub
    Private Sub LookDropButtonPK(ByVal l As Boolean)
        editmapk.Enabled = Not l
        edittenpk.Enabled = Not l
        editdvtinhpk.Enabled = Not l
        editgiapk.Enabled = Not l
    End Sub
    Private Function TestTextboxPK()
        If (Trim(txtmapk.Text) = "" Or Trim(txttenpk.Text) = "" Or Trim(txtdvtinhpk.Text) = "" Or Trim(txtgiapk.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin", MsgBoxStyle.Exclamation, "Thông báo")
            testpk = 0
        Else
            testpk = 1
        End If
        Return testpk
    End Function
    Private Sub ClearBindingPK()
        txtmapk.DataBindings.Clear()
        txttenpk.DataBindings.Clear()
        txtdvtinhpk.DataBindings.Clear()
        txtgiapk.DataBindings.Clear()
    End Sub
    Private Sub ClearTextboxPK()
        txtmapk.Text = ""
        txttenpk.Text = ""
        txtdvtinhpk.Text = ""
        txtgiapk.Text = ""
    End Sub
    Private Sub editmapk_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmapk.TextChanged
        txtmapk.Text = editmapk.Text
    End Sub
    Private Sub edittenpk_TextChanged(sender As System.Object, e As System.EventArgs) Handles edittenpk.TextChanged
        txttenpk.Text = edittenpk.Text
    End Sub
    Private Sub editdvtinhpk_TextChanged(sender As System.Object, e As System.EventArgs) Handles editdvtinhpk.TextChanged
        txtdvtinhpk.Text = editdvtinhpk.Text
    End Sub
    Private Sub editgiapk_TextChanged(sender As System.Object, e As System.EventArgs) Handles editgiapk.TextChanged
        txtgiapk.Text = editgiapk.Text
    End Sub
    Private Sub btnaddpk_Click(sender As System.Object, e As System.EventArgs) Handles btnaddpk.Click
        flagpk = 1
        ClearBindingPK()
        ClearTextboxPK()
        LookButtonPK(True)
        LookDropButtonPK(False)
        txtmapk.Focus()
        txtmapk.Enabled = True
    End Sub
    Private Sub btneditpk_Click(sender As System.Object, e As System.EventArgs) Handles btneditpk.Click
        flagpk = 2
        LookButtonPK(True)
        LookDropButtonPK(False)
        txttenpk.Focus()
        txtmapk.Enabled = False
        editmapk.Enabled = False
    End Sub
    Private Sub btndeletepk_Click(sender As System.Object, e As System.EventArgs) Handles btndeletepk.Click
        Dim mapk As String = txtmapk.Text
        Dim tenpk As String = txttenpk.Text
        Dim dvtpk As String = txtdvtinhpk.Text
        Dim giapk As Single = Convert.ToSingle(txtgiapk.Text)
        Dim pkno = New phukienno(mapk, tenpk, giapk, dvtpk)
        bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) = Windows.Forms.DialogResult.Yes Then
            bus.DeletePK(pkno)
            ClearBindingPK()
            LoadDataPKNo()
            LookButtonPK(False)
            LookDropButtonPK(True)
            dgvpkno.RefreshDataSource()
            MsgBox("Bạn đã xóa thành công", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa", MsgBoxStyle.Exclamation, "Thông báo")
        End If
    End Sub

    Private Sub btnsavepk_Click(sender As System.Object, e As System.EventArgs) Handles btnsavepk.Click
        TestTextboxPK()
        If testpk = 1 Then
            Dim mapk As String = txtmapk.Text
            Dim tenpk As String = txttenpk.Text
            Dim dvtpk As String = txtdvtinhpk.Text
            Dim giapk As Single = Convert.ToSingle(txtgiapk.Text)
            Dim pkno = New phukienno(mapk, tenpk, giapk, dvtpk)
            bus = New knm2012BUS
            bus.InsertUpdatePK(pkno, flagpk)
            ClearBindingPK()
            LoadDataPKNo()
            LookButtonPK(False)
            LookDropButtonPK(True)
            dgvpkno.RefreshDataSource()
            txtmapk.Enabled = True
        End If
    End Sub
    Private Sub btncancelpk_Click(sender As System.Object, e As System.EventArgs) Handles btncancelpk.Click
        flagpk = 0
        ClearBindingPK()
        LoadDataPKNo()
        LookButtonPK(False)
        LookDropButtonPK(True)
        dgvpkno.RefreshDataSource()
        txtmapk.Enabled = True
    End Sub
    Private Sub btnclosepk_Click(sender As System.Object, e As System.EventArgs) Handles btnclosepk.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#End Region

#Region "page_laphochieuknm"

#Region "tabhochieukhoannomin"
    Dim flaghc As Integer = 0
    Dim testhc As Integer = 0
    Private Sub LoadDataHoChieu()
        dgvhochieu.RefreshDataSource()
        bus = New knm2012BUS
        Dim hcList As New List(Of hcknm)
        hcList = bus.GetDataHC()
        cm = Me.BindingContext(hcList)
        txtmahochieu.DataBindings.Add("Text", hcList, "Mahochieu")
        txtcongtruong.DataBindings.Add("Text", hcList, "Macongtruong")
        txtdocungdd.DataBindings.Add("Text", hcList, "Docung")
        txtmaykhoan.DataBindings.Add("Text", hcList, "Mamaykhoan")
        txtmayno.DataBindings.Add("Text", hcList, "Mamayno")
        txtppno.DataBindings.Add("Text", hcList, "Maphuongphapno")
        txtbatdau.DataBindings.Add("Text", hcList, "Thoigianbatdau")
        txtketthuc.DataBindings.Add("Text", hcList, "Thoigianketthuc")
        txtngay.DataBindings.Add("Text", hcList, "NgayNoMin")
        txtloaitn.DataBindings.Add("Text", hcList, "Loaithuocno")
        txtktm.DataBindings.Add("Text", hcList, "KTM")
        txtkxl.DataBindings.Add("Text", hcList, "KXL")
        dgvhochieu.DataSource = hcList
    End Sub
    Private Sub LookButtonHC(ByVal l As Boolean)
        btnaddhc.Enabled = Not l
        btnedithc.Enabled = Not l
        btndeletehc.Enabled = Not l
        btnsavehc.Enabled = l
        btncancelhc.Enabled = l
        btnclosehc.Enabled = Not l
    End Sub
    Private Sub LookDropButtonHC(ByVal l As Boolean)
        editmahochieu.Enabled = Not l
        editcongtruong.Enabled = Not l
        editdocungdd.Enabled = Not l
        editmaykhoan.Enabled = Not l
        editmayno.Enabled = Not l
        editppno.Enabled = Not l
        editbatdau.Enabled = Not l
        editketthuc.Enabled = Not l
        editngay.Enabled = Not l
        editloaitn.Enabled = Not l
        editktm.Enabled = Not l
        editkxl.Enabled = Not l
    End Sub
    Private Function TestTextboxHC()
        If (Trim(txtmahochieu.Text) = "" Or Trim(txtcongtruong.Text) = "" Or Trim(txtdocungdd.Text) = "" Or Trim(txtmaykhoan.Text) = "" Or Trim(txtmayno.Text) = "" Or Trim(txtppno.Text) = "" Or Trim(txtbatdau.Text) = "" Or Trim(txtketthuc.Text) = "" Or Trim(txtngay.Text) = "" Or Trim(txtloaitn.Text) = "" Or Trim(txtktm.Text) = "" Or Trim(txtkxl.Text) = "") Then
            MsgBox("Bạn phải nhập đầy đủ thông tin", MsgBoxStyle.Exclamation, "Thông báo")
            testhc = 0
        ElseIf ((CSng(txtdocungdd.Text) < 7) Or (CSng(txtdocungdd.Text) > 15)) Then
            MsgBox("Độ cứng giới hạn của loại đất đá ứng với loại thuốc nổ hiện tại từ 7 đến 15, vui lòng kiểm tra lại!", MsgBoxStyle.Exclamation, "Thông báo")
            testhc = 0
        Else
            testhc = 1
        End If
        Return testhc
    End Function
    Private Sub ClearBindingHC()
        txtmahochieu.DataBindings.Clear()
        txtcongtruong.DataBindings.Clear()
        txtdocungdd.DataBindings.Clear()
        txtmaykhoan.DataBindings.Clear()
        txtmayno.DataBindings.Clear()
        txtppno.DataBindings.Clear()
        txtbatdau.DataBindings.Clear()
        txtketthuc.DataBindings.Clear()
        txtngay.DataBindings.Clear()
        txtloaitn.DataBindings.Clear()
        txtktm.DataBindings.Clear()
        txtkxl.DataBindings.Clear()
    End Sub
    Private Sub ClearTextboxHC()
        txtmahochieu.Text = ""
        txtcongtruong.Text = ""
        txtdocungdd.Text = ""
        txtmaykhoan.Text = ""
        txtmayno.Text = ""
        txtppno.Text = ""
        txtbatdau.Text = ""
        txtketthuc.Text = ""
        txtngay.Text = ""
        txtloaitn.Text = ""
        txtktm.Text = ""
        txtkxl.Text = ""
    End Sub
    Private Sub editktm_TextChanged(sender As System.Object, e As System.EventArgs) Handles editktm.TextChanged
        txtktm.Text = editktm.Text
    End Sub
    Private Sub editkxl_TextChanged(sender As System.Object, e As System.EventArgs) Handles editkxl.TextChanged
        txtkxl.Text = editkxl.Text
    End Sub
    Private Sub editmahochieu_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmahochieu.TextChanged
        txtmahochieu.Text = editmahochieu.Text
    End Sub
    Private Sub editcongtruong_TextChanged(sender As System.Object, e As System.EventArgs) Handles editcongtruong.TextChanged
        txtcongtruong.Text = editcongtruong.Text
    End Sub
    Private Sub editdatda_TextChaged(sender As System.Object, e As System.EventArgs) Handles editdocungdd.TextChanged
        txtdocungdd.Text = editdocungdd.Text
    End Sub
    Private Sub editmaykhoan_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmaykhoan.TextChanged
        txtmaykhoan.Text = editmaykhoan.Text
    End Sub
    Private Sub editmayno_TextChanged(sender As System.Object, e As System.EventArgs) Handles editmayno.TextChanged
        txtmayno.Text = editmayno.Text
    End Sub
    Private Sub editppn_TextChanged(sender As System.Object, e As System.EventArgs) Handles editppno.TextChanged
        txtppno.Text = editppno.Text
    End Sub
    Private Sub editbatdau_TextChanged(sender As System.Object, e As System.EventArgs) Handles editbatdau.TextChanged
        txtbatdau.Text = editbatdau.Text
    End Sub
    Private Sub editketthuc_TextChanged(sender As System.Object, e As System.EventArgs) Handles editketthuc.TextChanged
        txtketthuc.Text = editketthuc.Text
    End Sub
    Private Sub editngay_TextChanged(sender As System.Object, e As System.EventArgs) Handles editngay.TextChanged
        txtngay.Text = editngay.Text
    End Sub
    Private Sub editloaitn_TextChanged(sender As System.Object, e As System.EventArgs) Handles editloaitn.TextChanged
        txtloaitn.Text = editloaitn.Text
    End Sub
    Private Sub btnaddhc_Click(sender As System.Object, e As System.EventArgs) Handles btnaddhc.Click
        flaghc = 1
        ClearBindingHC()
        ClearTextboxHC()
        LookButtonHC(True)
        LookDropButtonHC(False)
        txtmahochieu.Focus()
        txtmahochieu.Enabled = True
    End Sub
    Private Sub btnedithc_Click(sender As System.Object, e As System.EventArgs) Handles btnedithc.Click
        flaghc = 2
        LookButtonHC(True)
        LookDropButtonHC(False)
        txtcongtruong.Focus()
        txtmahochieu.Enabled = False
        editmahochieu.Enabled = False
    End Sub
    Private Sub btndeletehc_Click(sender As System.Object, e As System.EventArgs) Handles btndeletehc.Click
        Dim mahochieu As String = txtmahochieu.Text
        Dim macongtruong As String = txtcongtruong.Text
        Dim docung As Single = txtdocungdd.Text
        Dim mamaykhoan As String = txtmaykhoan.Text
        Dim mamayno As String = txtmayno.Text
        Dim mappn As String = txtppno.Text
        Dim tbatdau As String = txtbatdau.Text
        Dim tketthuc As String = txtketthuc.Text
        Dim ngaynomin As String = txtngay.Text
        Dim loaitn As String = txtloaitn.Text
        Dim ktm As String = txtktm.Text
        Dim kxl As String = txtkxl.Text
        Dim hochieu = New hcknm(mahochieu, macongtruong, docung, mamaykhoan, mamayno, mappn, tbatdau, tketthuc, ngaynomin, loaitn, ktm, kxl)
        bus = New knm2012BUS
        If (MessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) = Windows.Forms.DialogResult.Yes Then
            bus.DeleteHC(hochieu)
            ClearBindingHC()
            LoadDataHoChieu()
            LookButtonHC(False)
            LookDropButtonHC(True)
            dgvhochieu.RefreshDataSource()
            MsgBox("Bạn đã xóa thành công", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            MsgBox("Bạn đã hủy thao tác xóa", MsgBoxStyle.Exclamation, "Thông báo")
        End If
    End Sub

    Private Sub btnsavehc_Click(sender As System.Object, e As System.EventArgs) Handles btnsavehc.Click
        TestTextboxHC()
        If testhc = 1 Then
            Dim mahochieu As String = txtmahochieu.Text
            Dim macongtruong As String = txtcongtruong.Text
            Dim docung As Single = txtdocungdd.Text
            Dim mamaykhoan As String = txtmaykhoan.Text
            Dim mamayno As String = txtmayno.Text
            Dim mappn As String = txtppno.Text
            Dim tbatdau As String = txtbatdau.Text
            Dim tketthuc As String = txtketthuc.Text
            Dim ngaynomin As String = txtngay.Text
            Dim loaitn As String = txtloaitn.Text
            Dim ktm As String = txtktm.Text
            Dim kxl As String = txtkxl.Text
            Dim hochieu = New hcknm(mahochieu, macongtruong, docung, mamaykhoan, mamayno, mappn, tbatdau, tketthuc, ngaynomin, loaitn, ktm, kxl)
            bus = New knm2012BUS
            bus.InsertUpdateHC(hochieu, flaghc)
            ClearBindingHC()
            LoadDataHoChieu()
            LookButtonHC(False)
            LookDropButtonHC(True)
            dgvhochieu.RefreshDataSource()
            txtmahochieu.Enabled = True
        End If
    End Sub
    Private Sub btncancelhc_Click(sender As System.Object, e As System.EventArgs) Handles btncancelhc.Click
        flaghc = 0
        ClearBindingHC()
        LoadDataHoChieu()
        LookButtonHC(False)
        LookDropButtonHC(True)
        dgvhochieu.RefreshDataSource()
        txtmahochieu.Enabled = True
    End Sub
    Private Sub btnclosehc_Click(sender As System.Object, e As System.EventArgs) Handles btnclosehc.Click
        tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
    End Sub
#End Region

#Region "tabtinhtoan"
    Private Sub btntinhtoanhc_Click(sender As System.Object, e As System.EventArgs) Handles btntinhtoanhc.Click
        If Trim(txthochieutinhtoan.Text) <> "" Then
            Dim mahochieu As String = Trim(txthochieutinhtoan.Text)
            Dim ghichu As String = txtghichu.Text
            bus = New knm2012BUS
            bus.TinhToan(mahochieu, ghichu)
            LoadDataTinhToan(mahochieu)
        Else
            MsgBox("Vui lòng lựa chọn mã hộ chiếu để tính toán!", MsgBoxStyle.Exclamation, "Thông báo")
        End If
    End Sub
    Private Sub edithochieutinhtoan_TextChanged(sender As System.Object, e As System.EventArgs) Handles edithochieutinhtoan.TextChanged
        txthochieutinhtoan.Text = edithochieutinhtoan.Text
    End Sub
    Private Sub LoadDataTinhToan(ByVal mahochieu As String)
        bus = New knm2012BUS
        Dim ttlist As New List(Of ketquatinhtoan)
        ttlist = bus.GetDataTinhToan(mahochieu)
        dgvtinhtoan.DataSource = ttlist
    End Sub
    Private Sub btnpatch_Click(sender As System.Object, e As System.EventArgs) Handles btnpatch.Click
        Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
        Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
        If dlgResult = Windows.Forms.DialogResult.OK Then
            txtpatchsave_result.Text = MyFolderBrowser.SelectedPath
        End If
    End Sub
    Private Sub btnexport2excel_Click(sender As System.Object, e As System.EventArgs) Handles btnexport2excel.Click
        If Trim(txtpatchsave_result.Text) = "" Then
            MsgBox("Vui lòng chọn thư mục lưu file!", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            Dim filename As String = Trim(txthochieutinhtoan.Text)
            Dim filepatch As String = Trim(txtpatchsave_result.Text)
            Dim fullpatch As String = filepatch + "\" + filename + ".xls"
            Dim View As DevExpress.XtraGrid.Views.Grid.GridView = CType(dgvtinhtoan.MainView, DevExpress.XtraGrid.Views.Grid.GridView)
            If Not View Is Nothing Then
                View.OptionsPrint.ExpandAllDetails = True
                View.ExportToXls(fullpatch)
                Dim xlsExport = New Process
                xlsExport.StartInfo.FileName = "EXCEL.EXE"
                xlsExport.StartInfo.Arguments = fullpatch
                xlsExport.Start()
            End If
        End If
        'dgvtinhtoan.ExportToXls("ketquatinhtoan.xls")
    End Sub
    Private Sub btnexport2pdf_Click(sender As System.Object, e As System.EventArgs) Handles btnexport2pdf.Click
        If Trim(txtpatchsave_result.Text) = "" Then
            MsgBox("Vui lòng chọn thư mục lưu file", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            Dim filename As String = Trim(txthochieutinhtoan.Text)
            Dim filepatch As String = Trim(txtpatchsave_result.Text)
            Dim fullpatch As String = filepatch + "\" + filename + ".pdf"
            Dim View As DevExpress.XtraGrid.Views.Grid.GridView = CType(dgvtinhtoan.MainView, DevExpress.XtraGrid.Views.Grid.GridView)
            If Not View Is Nothing Then
                View.OptionsPrint.ExpandAllDetails = True
                View.ExportToPdf(fullpatch)
                Dim pdfExport = New Process
                pdfExport.StartInfo.FileName = "AcroRd32"
                pdfExport.StartInfo.Arguments = fullpatch
                pdfExport.Start()
            End If
        End If
    End Sub

    Private Sub btnprintresult_Click(sender As System.Object, e As System.EventArgs) Handles btnprintresult.Click
        dgvtinhtoan.ShowPrintPreview()
    End Sub
#End Region

#Region "tabxemlaihochieudatinhtoan"
    Private Sub edithochieudatinhtoan_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles edithochieudatinhtoan.EditValueChanged
        Dim mahochieu As String
        bus = New knm2012BUS
        Dim ttlist As New List(Of ketquatinhtoan)
        mahochieu = Trim(edithochieudatinhtoan.Text)
        ttlist = bus.GetDataDaTinhToan(mahochieu)
        dgvhcdatinhtoan.DataSource = ttlist
    End Sub
    Private Sub btnpatchsaveview_Click(sender As System.Object, e As System.EventArgs) Handles btnpatchsaveview.Click
        Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
        Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
        If dlgResult = Windows.Forms.DialogResult.OK Then
            txtpatchsaveview.Text = MyFolderBrowser.SelectedPath
        End If
    End Sub

    Private Sub btnexp2xls_Click(sender As System.Object, e As System.EventArgs) Handles btnexp2xls.Click
        If Trim(txtpatchsaveview.Text) = "" Then
            MsgBox("Vui lòng lựa chọn thư mục lưu file!", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            Dim filename As String = Trim(edithochieudatinhtoan.Text)
            Dim filepatch As String = Trim(txtpatchsaveview.Text)
            Dim fullpatch As String = filepatch + "\" + filename + ".xls"
            Dim View As DevExpress.XtraGrid.Views.Grid.GridView = CType(dgvhcdatinhtoan.MainView, DevExpress.XtraGrid.Views.Grid.GridView)
            If Not View Is Nothing Then
                View.OptionsPrint.ExpandAllDetails = True
                View.ExportToXls(fullpatch)
                Dim xlsExport = New Process
                xlsExport.StartInfo.FileName = "EXCEL.EXE"
                xlsExport.StartInfo.Arguments = fullpatch
                xlsExport.Start()
            End If
        End If
    End Sub
    Private Sub btnexp2pdf_Click(sender As System.Object, e As System.EventArgs) Handles btnexp2pdf.Click
        If Trim(txtpatchsaveview.Text) = "" Then
            MsgBox("Vui lòng lựa chọn thư mục lưu file!", MsgBoxStyle.Exclamation, "Thông báo")
        Else
            Dim filename As String = Trim(edithochieudatinhtoan.Text)
            Dim filepatch As String = Trim(txtpatchsaveview.Text)
            Dim fullpatch As String = filepatch + "\" + filename + ".pdf"
            Dim View As DevExpress.XtraGrid.Views.Grid.GridView = CType(dgvhcdatinhtoan.MainView, DevExpress.XtraGrid.Views.Grid.GridView)
            If Not View Is Nothing Then
                View.OptionsPrint.ExpandAllDetails = True
                View.ExportToPdf("Ketquatinhtoan.pdf")
                Dim pdfExport = New Process
                pdfExport.StartInfo.FileName = "AcroRd32"
                pdfExport.StartInfo.Arguments = "Ketquatinhtoan.pdf"
                pdfExport.Start()
            End If
        End If
    End Sub
    Private Sub btnexp2print_Click(sender As System.Object, e As System.EventArgs) Handles btnexp2print.Click
        dgvhcdatinhtoan.ShowPrintPreview()
    End Sub
#End Region

#Region "tablapbanve"
    Private Sub ProcGetPoint(ByVal hLcWnd As Integer, ByVal hView As Integer, ByVal Index As Integer, ByVal X As Double, ByVal Y As Double)
        Dim x0, y0, x4, y4 As Double
        If Index = 1 Then
            Lcad.WndGetPointBuf(hLcWnd, 0, x0, y0)
            Lcad.ViewDrawMarker(hView, x0, y0)
            Lcad.ViewDrawLine(hView, x0, y0, X, Y)
        End If
        If Index = 2 Then
            Lcad.WndGetPointBuf(hLcWnd, 0, x0, y0)
            Lcad.ViewDrawMarker(hView, x0, y0)
            Lcad.ViewDrawLine(hView, x0, y0, X, Y)

            Lcad.WndGetPointBuf(hLcWnd, 1, x4, y4)
            Lcad.ViewDrawMarker(hView, x4, y4)
            Lcad.ViewDrawLine(hView, x4, y4, X, Y)
        End If
    End Sub
    Private Sub ProcMouseDown(hLcWnd As Integer, Button As Integer, Flags As Integer, Xwin As Integer, Ywin As Integer, X As Double, Y As Double)
        TextEdit1.Text = (Convert.ToSingle(X)).ToString() + "," + (Convert.ToSingle(Y)).ToString()
    End Sub

    Private Sub ProcGripMove(ByVal hEnt As Integer, ByVal iGrip As Integer, ByRef pX As Double, ByRef pY As Double, ByRef pAngle As Double, ByVal bDrag As Boolean)
        TextEdit1.Text = iGrip.ToString() + "," + pX.ToString() + "," + pY.ToString()
    End Sub
    Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Lcad.GetClientSize(Handle, SplitContainer1.Width, SplitContainer1.Height)
        If hLcWnd <> 0 Then
            Lcad.CmdwinResize(hLcCmd, 0, 0, SplitContainer5.Panel1.Width, SplitContainer5.Panel1.Height)
            Lcad.PropwinResize(hLcProp, 0, 0, SplitContainer4.Panel1.Width, SplitContainer4.Panel1.Height)
            Lcad.WndResize(hLcWnd, 0, 0, SplitContainer3.Panel2.Width, SplitContainer3.Panel2.Height)
            Lcad.WndRedraw(hLcWnd)
        End If
    End Sub
    'Private Sub CreateDrawingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 
    '    Dim hLayer As Integer, hBlock As Integer, hView As Integer, hEnt As Integer, hPline As Integer
    '    Dim sText As String
    '    ' clear a drawing
    '    Lcad.DrwNew(hLcDrw, "", hLcWnd)
    '    ' get "Model Space" block
    '    hBlock = Lcad.PropGetHandle(hLcDrw, LC_PROP_DRW_BLOCK_MODEL)
    '    ' add lines
    '    Lcad.BlockAddLine(hBlock, 0, 0, 100, 100)
    '    Lcad.BlockAddLine(hBlock, 50, 0, 100, 50)
    '    ' add circle
    '    hEnt = Lcad.BlockAddCircle(hBlock, 60, 40, 10, 0)
    '    ' change the circle's color (use RGB)
    '    Lcad.PropPutStr(hEnt, Lcad.LC_PROP_ENT_COLOR, "128,200,250")
    '    ' add text
    '    Lcad.BlockAddText2(hBlock, "The Text", 0, 50, LC_TA_LEFBOT, 5, 0.8, 45 * LC_DEG_TO_RAD, 0)
    '    ' set current color (use AutoCAD color index)
    '    Lcad.PropPutStr(hLcDrw, LC_PROP_DRW_COLOR, "45")
    '    ' add text
    '    sText = Lcad.PropGetStr(0, Lcad.LC_PROP_G_DIRDLL)
    '    Lcad.BlockAddText2(hBlock, sText, 0, 20, LC_TA_LEFBOT, 5, 0.8, 0, 0)
    '    ' set current color "ByLayer"
    '    Lcad.PropPutStr(hLcDrw, LC_PROP_DRW_COLOR, "ByLayer")
    '    ' add new layer
    '    hLayer = Lcad.DrwAddLayer(hLcDrw, "Vertices", "green", 0, LC_LWEIGHT_000)
    '    ' set current layer
    '    Lcad.PropPutHandle(hLcDrw, LC_PROP_DRW_LAYER, hLayer)
    '    ' add polyline
    '    hPline = Lcad.BlockAddPolyline(hBlock, LC_PLFIT_QUAD, True, False)
    '    Lcad.PlineAddVer(hPline, 0, 20, 80)
    '    Lcad.PlineAddVer(hPline, 0, 30, 90)
    '    Lcad.PlineAddVer(hPline, 0, 50, 70)
    '    Lcad.PlineAddVer(hPline, 0, 33, 63)
    '    Lcad.PlineAddVer(hPline, 0, 20, 50)

    '    Lcad.DrwRegenViews(hLcDrw, 0)
    '    ' hide grid
    '    hView = Lcad.PropGetHandle(hLcDrw, LC_PROP_DRW_VIEW_MODEL)
    '    Lcad.PropPutBool(hView, LC_PROP_VIEW_GRID, False)
    '    ' Zoom extents
    '    Lcad.WndExeCommand(hLcWnd, Lcad.LC_CMD_ZOOM_EXT, 0)
    'End Sub

    Private Sub ProcAddCommand(ByVal hLcWnd As Integer)
        Lcad.CreateCommand(hLcWnd, MYCMD_SKETCH, "SKETCH", False)
    End Sub
    Private Sub ProcCmdStart(ByVal hCmd As Integer, ByVal Prm As Integer)
        Dim Id As Integer
        Id = Lcad.PropGetInt(hCmd, LC_PROP_CMD_ID)
        If Id = MYCMD_SKETCH Then
            Lcad.PropPutInt(hCmd, LC_PROP_CMD_INT0, 0)   ' do not draw
            Lcad.PropPutHandle(hCmd, LC_PROP_CMD_HAND0, 0) ' polyline
        End If
    End Sub
    Private Sub ProcCmdFinish(ByVal hCmd As Integer)
        Dim Id As Integer
        Id = Lcad.PropGetInt(hCmd, LC_PROP_CMD_ID)
        If Id = MYCMD_SKETCH Then

        End If
    End Sub
    Private Sub ProcCmdMouseDown(ByVal hCmd As Integer, ByVal Button As Integer, ByVal Flags As Integer, ByVal Xwin As Integer, ByVal Ywin As Integer, ByVal X As Double, ByVal Y As Double)
        Dim Id As Integer
        Dim hBlock As Integer, hPline As Integer

        Id = Lcad.PropGetInt(hCmd, LC_PROP_CMD_ID)
        If Id = MYCMD_SKETCH Then
            If Button = LC_LBUTTON Then
                hBlock = Lcad.PropGetHandle(hCmd, LC_PROP_CMD_BLOCK)
                hPline = Lcad.BlockAddPolyline(hBlock, 0, False, False)
                Lcad.PropPutHandle(hCmd, LC_PROP_CMD_HAND0, hPline)  ' polyline
                Lcad.PropPutInt(hCmd, LC_PROP_CMD_INT0, 1)   ' draw
            ElseIf Button = LC_RBUTTON Then
                Lcad.CmdExit()  ' exit command
            End If
        End If
    End Sub
    Private Sub ProcCmdMouseUp(ByVal hCmd As Integer, ByVal Button As Integer, ByVal Flags As Integer, ByVal Xwin As Integer, ByVal Ywin As Integer, ByVal X As Double, ByVal Y As Double)
        Dim Id As Integer
        Id = Lcad.PropGetInt(hCmd, LC_PROP_CMD_ID)
        If Id = MYCMD_SKETCH Then
            If Button = LC_LBUTTON Then
                Lcad.PropPutInt(hCmd, LC_PROP_CMD_INT0, 0)  ' do not draw
            End If
        End If
    End Sub
    Private Sub ProcCmdMouseMove(ByVal hCmd As Integer, ByVal hDC As Integer, ByVal Flags As Integer, ByVal Xwin As Integer, ByVal Ywin As Integer, ByVal X As Double, ByVal Y As Double)
        Dim Id As Integer
        Dim hPline As Integer, bDraw As Integer

        Id = Lcad.PropGetInt(hCmd, LC_PROP_CMD_ID)
        If Id = MYCMD_SKETCH Then
            bDraw = Lcad.PropGetInt(hCmd, LC_PROP_CMD_INT0)
            If bDraw = 1 Then
                hPline = Lcad.PropGetHandle(hCmd, LC_PROP_CMD_HAND0)
                Lcad.PlineAddVer(hPline, 0, X, Y)
                Lcad.CmdRegen(hCmd, hPline)
                Lcad.CmdRedraw(hCmd)
            End If
        End If
    End Sub
    Private Sub ProcCmdString(ByVal hCmd As Integer, ByVal szStr As String)
        Dim Id As Integer
        Id = Lcad.PropGetInt(hCmd, LC_PROP_CMD_ID)
        If Id = MYCMD_SKETCH Then

        End If
    End Sub

    Private Sub btnexitcad_Click(sender As System.Object, e As System.EventArgs) Handles btnexitcad.Click
        If MessageBox.Show("Đóng CAD? (chú ý: bản vẽ hiện tại sẽ không được lưu)", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            Lcad.CmdExit()
            btnnew.PerformClick()
            tabcontrol.TabPages.RemoveAt(tabcontrol.SelectedTabPageIndex)
        End If
    End Sub

    Private Sub btnnew_Click(sender As System.Object, e As System.EventArgs) Handles btnnew.Click
        Lcad.DrwNew(hLcDrw, "", hLcWnd)
    End Sub
    Private Sub btnopen_Click(sender As System.Object, e As System.EventArgs) Handles btnopen.Click
        Lcad.DrwLoad(hLcDrw, "<Dialog>", Handle, hLcWnd)
    End Sub
    Private Sub btnsaveas_Click(sender As System.Object, e As System.EventArgs) Handles btnsaveas.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_FILESAVEAS, 0)
    End Sub
    Private Sub btnsaved_Click(sender As System.Object, e As System.EventArgs) Handles btnsaved.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_FILESAVE, 0)
    End Sub
    Private Sub btnprint_Click(sender As System.Object, e As System.EventArgs) Handles btnprint.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_PRINT, 0)
    End Sub
    Private Sub btncut_Click(sender As System.Object, e As System.EventArgs) Handles btncut.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_CBCUT, 0)
    End Sub
    Private Sub coppy_Click(sender As System.Object, e As System.EventArgs) Handles btncoppy.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_CBCOPY, 0)
    End Sub
    Private Sub btnpaste_Click(sender As System.Object, e As System.EventArgs) Handles btnpaste.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_CBPASTE, 0)
    End Sub
    Private Sub btnundo_Click(sender As System.Object, e As System.EventArgs) Handles btnundo.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_UNDO, 0)
    End Sub
    Private Sub btnredo_Click(sender As System.Object, e As System.EventArgs) Handles btnredo.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_REDO, 0)
    End Sub
    Private Sub btnpan_Click(sender As System.Object, e As System.EventArgs) Handles btnpan.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_PAN_RT, 0)
    End Sub
    Private Sub btnzoom_Click(sender As System.Object, e As System.EventArgs) Handles btnzoom.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_ZOOM_RT, 0)
    End Sub

    Private Sub btncolor_Click(sender As System.Object, e As System.EventArgs) Handles btncolor.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_COLOR, 0)
    End Sub
    Private Sub btnlayer_Click(sender As System.Object, e As System.EventArgs) Handles btnlayer.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_LAYER, 0)
    End Sub

    Private Sub btnlinetype_Click(sender As System.Object, e As System.EventArgs) Handles btnlinetype.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_LINETYPE, 0)
    End Sub
    Private Sub btnlineweight_Click(sender As System.Object, e As System.EventArgs) Handles btnlineweight.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_LWEIGHT, 0)
    End Sub

    Private Sub btntextstyle_Click(sender As System.Object, e As System.EventArgs) Handles btntextstyle.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_TEXTSTYLE, 0)
    End Sub

    Private Sub btnblog_Click(sender As System.Object, e As System.EventArgs) Handles btnblog.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_BLOCKS, 0)
    End Sub


    Private Sub btnpoint_Click(sender As System.Object, e As System.EventArgs) Handles btnpoint.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_POINT, 0)
    End Sub

    Private Sub btnline_Click(sender As System.Object, e As System.EventArgs) Handles btnline.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_LINE, 0)
    End Sub

    Private Sub btnpolyline_Click(sender As System.Object, e As System.EventArgs) Handles btnpolyline.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_POLYLINE, 0)
    End Sub

    Private Sub btnspline_Click(sender As System.Object, e As System.EventArgs) Handles btnspline.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SPLINE, 0)
    End Sub

    Private Sub btnmultiline_Click(sender As System.Object, e As System.EventArgs) Handles btnmultiline.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_MLINE, 0)
    End Sub

    Private Sub btnrectangle_Click(sender As System.Object, e As System.EventArgs) Handles btnrectangle.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_RECT, 0)
    End Sub

    Private Sub btncircle_Click(sender As System.Object, e As System.EventArgs) Handles btncircle.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_CIRCLE, 0)
    End Sub

    Private Sub btnarc_Click(sender As System.Object, e As System.EventArgs) Handles btnarc.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_ARC, 0)
    End Sub

    Private Sub btnellipse_Click(sender As System.Object, e As System.EventArgs) Handles btnellipse.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_ELLIPSE, 0)
    End Sub

    Private Sub btntext_Click(sender As System.Object, e As System.EventArgs) Handles btntext.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_TEXT, 0)
    End Sub
    Private Sub btnbound_Click(sender As System.Object, e As System.EventArgs) Handles btnbound.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_BOUNDARY, 0)
    End Sub

    Private Sub btnhatch_Click(sender As System.Object, e As System.EventArgs) Handles btnhatch.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_HATCH, 0)
    End Sub

    Private Sub btncreateblock_Click(sender As System.Object, e As System.EventArgs) Handles btncreateblock.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_BLOCK, 0)
    End Sub

    Private Sub btninsertblock_Click(sender As System.Object, e As System.EventArgs) Handles btninsertblock.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_INSERT, 0)
    End Sub

    Private Sub btneraser_Click(sender As System.Object, e As System.EventArgs) Handles btneraser.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_ERASE, 0)
    End Sub

    Private Sub btncopy_Click(sender As System.Object, e As System.EventArgs) Handles btncopy.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_COPY, 0)
    End Sub

    Private Sub btnmove_Click(sender As System.Object, e As System.EventArgs) Handles btnmove.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_MOVE, 0)
    End Sub

    Private Sub btnrotate_Click(sender As System.Object, e As System.EventArgs) Handles btnrotate.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_ROTATE, 0)
    End Sub

    Private Sub btnscale_Click(sender As System.Object, e As System.EventArgs) Handles btnscale.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SCALE, 0)
    End Sub

    Private Sub btnmirror_Click(sender As System.Object, e As System.EventArgs) Handles btnmirror.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_MIRROR, 0)
    End Sub

    Private Sub btntrim_Click(sender As System.Object, e As System.EventArgs) Handles btntrim.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_TRIM, 0)
    End Sub

    Private Sub btnextend_Click(sender As System.Object, e As System.EventArgs) Handles btnextend.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_EXTEND, 0)
    End Sub

    Private Sub btnbr2front_Click(sender As System.Object, e As System.EventArgs) Handles btnbr2front.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_VIEW_FRONT, 0)
    End Sub

    Private Sub btnsend2back_Click(sender As System.Object, e As System.EventArgs) Handles btnsend2back.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_VIEW_BACK, 0)
    End Sub
    Private Sub btnendp_Click(sender As System.Object, e As System.EventArgs) Handles btnendp.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SNAP_ENDPOINT, 0)
    End Sub

    Private Sub btnsnapmid_Click(sender As System.Object, e As System.EventArgs) Handles btnsnapmid.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SNAP_MIDPOINT, 0)
    End Sub
    Private Sub btndrafting_Click(sender As System.Object, e As System.EventArgs) Handles btndrafting.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_GRID, 0)
    End Sub

    Private Sub btnoption_Click(sender As System.Object, e As System.EventArgs) Handles btnoption.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_OPTIONS, 0)
    End Sub

    Private Sub btnsnap_Click(sender As System.Object, e As System.EventArgs) Handles btnsnap.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SW_GRIDSNAP, 0)
    End Sub
    Private Sub btngrid_Click(sender As System.Object, e As System.EventArgs) Handles btngrid.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SW_GRID, 0)
    End Sub
    Private Sub btnortho_Click(sender As System.Object, e As System.EventArgs) Handles btnortho.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SW_ORTHO, 0)
    End Sub
    Private Sub btnpolar_Click(sender As System.Object, e As System.EventArgs) Handles btnpolar.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SW_POLAR, 0)
    End Sub
    Private Sub btnosnap_Click(sender As System.Object, e As System.EventArgs) Handles btnosnap.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SW_OSNAP, 0)
    End Sub
    Private Sub btnlightweight_Click(sender As System.Object, e As System.EventArgs) Handles btnlineweight.Click
        Lcad.WndExeCommand(hLcWnd, LC_CMD_SW_LWEIGHT, 0)
    End Sub


#End Region

#End Region

#Region "page_tienich_hdsd"
    Private Sub btnemail_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnemail.ItemClick
        frm_email.Show()
    End Sub

    Private Sub btnemailfeedback_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnemailfeedback.ItemClick
        frm_email.Show()
    End Sub
#End Region


    Private Sub btnhcdung_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnhcdung.ItemClick
        Dim mahochieu As String = txthcve.Text
        VeHinhChieuDung(mahochieu)
    End Sub
    Private Sub VeHinhChieuDung(ByVal mahochieu As String)
        Dim macongtruong As String
        Dim Lct As Single
        Dim w As Single
        Dim a As Single
        Dim Lb As Single
        Dim Lt As Single
        Dim Lk As Single
        Dim Lkt As Single
        bus = New knm2012BUS
        macongtruong = bus.GetDataCongTruong(mahochieu)
        Lct = bus.GetDataLct(mahochieu)
        w = bus.GetDattaw(mahochieu)
        a = bus.GetDataa(mahochieu)
        Lb = bus.GetDataLb(mahochieu)
        Lt = bus.GetDataLt(mahochieu)
        Lk = bus.GetDataLK(mahochieu)
        Lkt = bus.GetDataLkt(mahochieu)
        Lcad.DrwLoad(hLcDrw, "hcdung.lcd", SplitContainer3.Panel2.Handle, hLcWnd)
        hView = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_VIEW)
        hBlock = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_BLOCK)
        Lcad.BlockAddText2(hBlock, "Công trường = " + macongtruong, -28.0, 46.5, Lcad.LC_TA_LEFCEN, 1, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "H = " + Convert.ToString(Lct), -58.0, 41.0, Lcad.LC_TA_LEFCEN, 1, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "W = " + Convert.ToString(w), -58.0, 39.0, Lcad.LC_TA_LEFCEN, 1, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "a = " + Convert.ToString(a), -58.0, 37.0, Lcad.LC_TA_LEFCEN, 1, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "Lt = " + Convert.ToString(Lt), -58.0, 35.0, Lcad.LC_TA_LEFCEN, 1, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "Lk = " + Convert.ToString(Lk), -58.0, 33.0, Lcad.LC_TA_LEFCEN, 1, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "Lkt = " + Convert.ToString(Lkt), -58.0, 31.0, Lcad.LC_TA_LEFCEN, 1, 0, 0, 0)
        Lcad.DrwRegenViews(hLcDrw, 0)
        Lcad.WndRedraw(hLcWnd)
    End Sub


    
    Private Sub btnhcbang_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnhcbang.ItemClick
        Dim mahochieu As String = txthcve.Text
        VeHinhChieuBang(mahochieu)
    End Sub
    Private Sub VeHinhChieuBang(ByVal mahochieu As String)
        Dim macongtruong As String
        Dim w As Single
        Dim a As Single
        Dim b As Single
        macongtruong = bus.GetDataCongTruong(mahochieu)
        w = bus.GetDattaw(mahochieu)
        a = bus.GetDataa(mahochieu)
        b = bus.GetDatab(mahochieu)
        Lcad.DrwLoad(hLcDrw, "hcbang.lcd", SplitContainer3.Panel2.Handle, hLcWnd)
        hView = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_VIEW)
        hBlock = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_BLOCK)
        Lcad.BlockAddText2(hBlock, "Công trường = " + macongtruong, -32.0, 24, Lcad.LC_TA_LEFCEN, 2.3, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "W = " + Convert.ToString(w), -76.0, 10, Lcad.LC_TA_LEFCEN, 2.3, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "a = " + Convert.ToString(a), -76.0, 6, Lcad.LC_TA_LEFCEN, 2.3, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "b = " + Convert.ToString(b), -76.0, 2, Lcad.LC_TA_LEFCEN, 2.3, 0, 0, 0)
        Lcad.DrwRegenViews(hLcDrw, 0)
        Lcad.WndRedraw(hLcWnd)
    End Sub

    Private Sub btndieukhienno_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btndieukhienno.ItemClick
        Dim mahochieu As String = txthcve.Text
        VeSoDoDK(mahochieu)
    End Sub
    Private Sub VeSoDoDK(ByVal mahochieu As String)
        Dim macongtruong As String
        Dim w As Single
        Dim a As Single
        Dim b As Single
        macongtruong = bus.GetDataCongTruong(mahochieu)
        w = bus.GetDattaw(mahochieu)
        a = bus.GetDataa(mahochieu)
        b = bus.GetDatab(mahochieu)
        Lcad.DrwLoad(hLcDrw, "sododk.lcd", SplitContainer3.Panel2.Handle, hLcWnd)
        hView = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_VIEW)
        hBlock = Lcad.DrwGetFirstObject(hLcDrw, Lcad.LC_OBJ_BLOCK)
        Lcad.BlockAddText2(hBlock, "Công trường = " + macongtruong, -32.0, 24, Lcad.LC_TA_LEFCEN, 2.3, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "W = " + Convert.ToString(w), -76.0, 10, Lcad.LC_TA_LEFCEN, 2.3, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "a = " + Convert.ToString(a), -76.0, 6, Lcad.LC_TA_LEFCEN, 2.3, 0, 0, 0)
        Lcad.BlockAddText2(hBlock, "b = " + Convert.ToString(b), -76.0, 2, Lcad.LC_TA_LEFCEN, 2.3, 0, 0, 0)
        Lcad.DrwRegenViews(hLcDrw, 0)
        Lcad.WndRedraw(hLcWnd)
    End Sub
End Class